目录
一 设计原型
二 后台源码
一 设计原型
二 后台源码
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 工业自动化控制中心
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private int Count = 0;private bool IsStop = false;public delegate void Ac();private void Form1_Load(object sender, EventArgs e){Task.Factory.StartNew(() =>{while (true){if (IsStop){Count++;this.Invoke(new Ac(Test));}Thread.Sleep(1000);}});}private void uiTurnSwitch1_ValueChanged(object sender, bool value){IsStop = uiTurnSwitch1.Active;if (!IsStop){hslVacuumPump1.MoveSpeed = 0;hslCoolFan1.MoveSpeed = 0;hslDialPlate1.Value = 0;}}public void Test(){hslVacuumPump1.MoveSpeed = new Random().Next(30, 100);hslCoolFan1.MoveSpeed = new Random().Next(80, 100);hslDialPlate1.Value = new Random().Next(80, 100);int A = new Random().Next(888888, 989888778);int B = new Random().Next(787867, 989888778);int C = new Random().Next(78767, 989888778);int D = new Random().Next(546456, 989888778);int E = new Random().Next(989887, 98988778);int F = new Random().Next(3234234, 98988778);int G = new Random().Next(5645654, 98988778);int H = new Random().Next(5464564, 98988778);string Result = "OK";string DateTimes = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");uiDataGridView1.Rows.Add(A, B, C, D, E, F, G, H, Result, DateTimes);//始终滚动到最后一行uiDataGridView1.FirstDisplayedScrollingRowIndex = uiDataGridView1.Rows.Count - 1;//限制仅展示50条数据if (uiDataGridView1.Rows.Count > 30){uiDataGridView1.Rows.RemoveAt(uiDataGridView1.Rows.Count - 2);}}}
}