代码拉取完成,页面将自动刷新
同步操作将从 逸哥哥/WLW_Electricity_detection 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WLW_Electricity_detection
{
public partial class Form_主页面 : Form
{
Form_串口配置 Form_串口配置_obj = new Form_串口配置();
Form_阈值配置 Form_阈值配置_obj = new Form_阈值配置();
Thread update_voltage_th = null;
SynchronizationContext Assistant = null;
bool LED_flicker = false;
bool LED_state = false;
public Form_主页面()
{
InitializeComponent();
Assistant = SynchronizationContext.Current;
startThread();
timer_电压.Start();
}
public class CustomProgressBar : ProgressBar
{
public CustomProgressBar()
{
base.SetStyle(ControlStyles.UserPaint, true);
//...
}
//重写baiOnPaint方法
protected override void OnPaint(PaintEventArgs e)
{
SolidBrush brush = null;
Pen pen;
Rectangle bounds = new Rectangle(0, 0, base.Width, base.Height);
//...
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, bounds.Width - 2, bounds.Height - 2);
bounds.Height -= 4;
bounds.Width = ((int)(bounds.Width * (((double)base.Value) / ((double)base.Maximum)))) - 4;
brush = new SolidBrush(Color.Yellow);
e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);
}
}
void startThread() // 线程启动函数
{
update_voltage_th = new Thread(update_voltage);
update_voltage_th.Start();
}
void update_voltage()
{
while (true)
{
if(label_电压.Text != Share.val && Share.val != "")
Assistant.Post(update, Share.val);
Assistant.Post(Real_time, null);
Thread.Sleep(100);
}
}
void Real_time(object obj)
{
label_实时时间.Text = DateTime.Now.ToString();
}
void update(object obj)
{
string str = (string)obj;
label_电压.Text = str;
chart_电压.Series["电压"].Points.AddXY(Share.val_time, str);
int index = this.dataGridView_记录电压.Rows.Add();
this.dataGridView_记录电压.Rows[index].Cells[0].Value = Share.val_time;
this.dataGridView_记录电压.Rows[index].Cells[1].Value = str;
this.dataGridView_记录电压.FirstDisplayedScrollingRowIndex = index;
unpack(str);
label_时间.Text = Share.val_time;
progressBar_进度.Maximum = (int)(Share.order * 10);
if ((int)(Share.order * 10) >= (int)(double.Parse(Share.val) * 10))
{
progressBar_进度.Value = (int)(double.Parse(Share.val) * 10);
}
else
{
progressBar_进度.BackColor = Color.White;
progressBar_进度.Value = (int)(Share.order * 10);
}
}
void unpack(string val)
{
float num = float.Parse(val);
if (num >= Share.power_shortage_Q && num < Share.power_shortage)
{
LED_flicker = false;
label_变化灯.ForeColor = Color.Black;
}
else if (num >= Share.power_shortage && num < Share.low_energy)
{
LED_flicker = false;
label_变化灯.ForeColor = Color.Yellow;
}
else if (num >= Share.low_energy && num < Share.order)
{
LED_flicker = false;
label_变化灯.ForeColor = Color.Green;
}
else if (num >= Share.order && num < Share.fully_loaded)
LED_flicker = true;
}
private void Form_主页面_Load(object sender, EventArgs e)
{
}
private void 串口配置ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form_串口配置_obj.Show();
}
private void 阈值配置ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form_阈值配置_obj.Show();
}
private void button_退出_Click(object sender, EventArgs e)
{
System.Environment.Exit(0);
}
private void timer_电压_Tick(object sender, EventArgs e)
{
if (LED_flicker)
{
if (LED_state)
{
LED_state = !LED_state;
label_变化灯.ForeColor = Color.Red;
}
else
{
LED_state = !LED_state;
label_变化灯.ForeColor = Color.Black;
}
}
}
private void progressBar_进度_ControlAdded(object sender, ControlEventArgs e)
{
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。