1 Star 0 Fork 5

adslvcd/myIPC

forked from 13799673123/myIPC 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DriverForm.cs 8.51 KB
一键复制 编辑 原始数据 按行查看 历史
13799673123 提交于 2023-05-18 10:11 . 美化了菜单栏
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace UltrasonicTDPlatform
{
public partial class DriverForm : Form
{
int DriFreq = 20500; //驱动设置频率
int Drivol = 100; //驱动电压
int Dricur = 5; //驱动电流
int Dripow = 1000; //驱动功率
/*
* 用于存放显示数据的队列,以及队列的一些信息
*/
private Queue<double> dataQueue = new Queue<double>(100);
private int curValue = 0;
private int num = 5;//每次删除增加几个点
public DriverForm()
{
InitializeComponent();
this.TopLevel = false;
InitChart(chart1);
}
/// <summary>
/// 初始化图表
/// </summary>
private void InitChart(Chart chart)
{
//定义图表区域
chart.ChartAreas.Clear();
ChartArea chartArea1 = new ChartArea("C1");
chart.ChartAreas.Add(chartArea1);
chartArea1.BackColor = System.Drawing.Color.Transparent;
//定义存储和显示点的容器
chart.Series.Clear();
Series series1 = new Series("S1");
series1.ChartArea = "C1";
chart.Series.Add(series1);
//设置图表显示样式
chart.ChartAreas[0].AxisY.Minimum = 0;
chart.ChartAreas[0].AxisY.Maximum = 100;
chart.ChartAreas[0].AxisX.Interval = 5;
chart.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
chart.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
//设置标题
chart.Titles.Clear();
chart.Titles.Add("S01");
chart.Titles[0].Text = "驱动电压显示";
chart.Titles[0].ForeColor = Color.RoyalBlue;
chart.Titles[0].Font = new System.Drawing.Font("幼圆", 12F);
//隐藏图例
// Exclude entries from the legend.
chart.Legends[0].Enabled = false;
chart.ForeColor = Color.White;
//设置图表显示样式
double element = 100;
chart.ChartAreas[0].AxisY.Minimum = 0;
chart.ChartAreas[0].AxisY.Maximum = element;
chart.ChartAreas[0].AxisY.Interval = element / 5;
chart.ChartAreas[0].AxisX.Minimum = 0;
chart.ChartAreas[0].AxisX.Maximum = 100;
chart.ChartAreas[0].AxisX.Interval = 20;
chart.ChartAreas[0].AxisX.Title = "时间 / us";
chart.ChartAreas[0].AxisY.Title = "幅值 / V";
chart.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("幼圆", 12F);
chart.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("幼圆", 12F);
//图表字体颜色
chart.ChartAreas[0].AxisY.TitleForeColor = Color.Silver;
chart.ChartAreas[0].AxisX.TitleForeColor = Color.Silver;
chart.ChartAreas[0].AxisX.LineColor = Color.Silver;
chart.ChartAreas[0].AxisY.LineColor = Color.Silver;
chart.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Silver;
chart.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Silver;
chart.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Silver;
chart.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Silver;
//chart.ChartAreas[0].AxisY.
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "F0";//2位小数
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "F0";//3位小数
//设置图表显示样式
chart.Series[0].Color = Color.Red;
chart.Series[0].ChartType = SeriesChartType.Spline;
chart.Series[0].Points.Clear();
chart.Series[0].Points.AddXY(0, 0);
}
/// <summary>
/// 定时器事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
UpdateQueueValue();
this.chart1.Series[0].Points.Clear();
for (int i = 0; i < dataQueue.Count; i++)
{
this.chart1.Series[0].Points.AddXY((i + 1), dataQueue.ElementAt(i));
}
}
/// <summary>
/// 更新队列中的值
/// </summary>
private void UpdateQueueValue()
{
if (dataQueue.Count > 100)
{
//先出列
for (int i = 0; i < num; i++)
{
dataQueue.Dequeue();
}
}
for (int i = 0; i < num; i++)
{
//对curValue只取[0,360]之间的值
curValue = curValue % 360;
//对得到的正玄值,放大50倍,并上移50
dataQueue.Enqueue((50 * Math.Sin(curValue * Math.PI / 180)) + 50);
curValue = curValue + 10;
}
}
private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
{
}
private void DriverForm_Load(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
//相关值装载
NUDfreq.Value = DriFreq;
NUDCur.Value = Dricur;
NUDpow.Value = Dripow;
NUDvol.Value = Drivol;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
}
private void label1_Click_1(object sender, EventArgs e)
{
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void label9_Click(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged_2(object sender, EventArgs e)
{
if(RBCV.Checked||RBCP.Checked||RBCA.Checked)
{
CBRFT.Checked = false;
}
}
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
CBRFT.Checked = false;
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
CBRFT.Checked = false;
}
private void radioButton7_CheckedChanged(object sender, EventArgs e)
{
CBRFT.Checked = false;
}
private void button1_Click(object sender, EventArgs e)
{
if (!timer1.Enabled)
{
timer1.Start();
pictureBox1.BackgroundImage = Properties.Resources.jieshu;
pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
button1.Text = " 结束";
}
else
{
timer1.Stop();
pictureBox1.BackgroundImage = Properties.Resources.qidong;
pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
button1.Text = " 启动";
}
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
}
private void label25_Click(object sender, EventArgs e)
{
}
private void numericUpDown1_ValueChanged_1(object sender, EventArgs e)
{
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/adslvcd/my-ipc.git
git@gitee.com:adslvcd/my-ipc.git
adslvcd
my-ipc
myIPC
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385