📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.Xml;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Threading;
namespace HyperBarServer
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblCurrentCounter1;
private System.Windows.Forms.Label lblCurrentCounter;
private System.Windows.Forms.Label lblBaudrate;
private System.Windows.Forms.ComboBox cboBaudrates;
private System.Windows.Forms.ComboBox cboDisplayUnits;
private System.Windows.Forms.CheckBox chkAutoStartSampling;
private System.Windows.Forms.Label lblSecond1;
private System.Windows.Forms.CheckBox chkValidateCounters;
private System.Windows.Forms.Label lblSecond2;
private System.Windows.Forms.Label lblDisplayUnits;
private System.Windows.Forms.CheckBox chkDisplayUnitEnabled;
private System.Windows.Forms.CheckBox chkLogarithmic;
private System.Windows.Forms.ComboBox cboOperators;
private System.Windows.Forms.TabControl tabMain;
private System.Windows.Forms.TabPage pageGeneral;
private System.Windows.Forms.TabPage pageDisplay;
private System.Windows.Forms.TabPage pageRun;
private System.Windows.Forms.Button btnModifyCounter;
private System.Windows.Forms.ToolBar tbMain;
private System.Windows.Forms.ToolBarButton tbbSave;
private System.Windows.Forms.ToolBarButton tbbExit;
private System.Windows.Forms.CheckBox chkStartWithSys;
private System.Windows.Forms.CheckBox chkHideOnStart;
private System.Windows.Forms.Timer tmrSample;
private System.Windows.Forms.ToolBarButton tbbRun;
private System.Windows.Forms.ImageList ilTabCtrl;
private System.Windows.Forms.ImageList ilToolbar;
private System.Windows.Forms.ToolBarButton tbbSeparator1;
private System.Windows.Forms.ToolBarButton tbbAbout;
private System.Windows.Forms.ToolBarButton tbbHide;
private System.Windows.Forms.ToolBarButton tbbHelp;
private System.Windows.Forms.Label lblSampleInterval;
private System.Windows.Forms.ComboBox cboSampleIntervals;
private System.Windows.Forms.Label lblMillisecond1;
private System.Windows.Forms.ImageList ilCntStatus;
private System.Windows.Forms.ImageList ilDevStatus;
private System.Windows.Forms.Label lblDeviceStatus;
private System.Windows.Forms.ColumnHeader chUnitName;
private System.Windows.Forms.ColumnHeader chSampleValue;
private System.Windows.Forms.ColumnHeader chDisplayValue;
private System.Windows.Forms.ColumnHeader chCounter;
private System.Windows.Forms.CheckBox chkTraceData;
private System.Windows.Forms.Label lblMillisecond2;
private System.Windows.Forms.Label lblRefreshInterval;
private System.Windows.Forms.TextBox txtValidateInterval;
private System.Windows.Forms.Label lblValidateInterval;
private System.Windows.Forms.Label lblStartDelay;
private System.Windows.Forms.Label lblMinValue;
private System.Windows.Forms.TextBox txtMinValue;
private System.Windows.Forms.Label lblMaxValue;
private System.Windows.Forms.TextBox txtMaxValue;
private System.Windows.Forms.Label lblThreshold;
private System.Windows.Forms.TextBox txtThreshold;
private System.Windows.Forms.Label lblOperator;
private System.Windows.Forms.TextBox txtStartDelay;
private System.Windows.Forms.Timer tmrTrace;
private System.Windows.Forms.ListView lvTraceData;
private System.Windows.Forms.Timer tmrChkDev;
private System.Windows.Forms.ComboBox cboRefreshIntervals;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu mnuTray;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem mnuShowForm;
private System.Windows.Forms.MenuItem mnuMonitor;
private System.Windows.Forms.MenuItem mnuExit;
private System.Windows.Forms.Label lblSeparator1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Timer tmrValidate;
private System.Windows.Forms.ErrorProvider errorProvider1;
private System.Windows.Forms.Label lblAvrLogo1;
private System.Windows.Forms.ImageList ilAvrLogo;
private System.Windows.Forms.Label lblAvrLogo2;
private System.Windows.Forms.Timer tmrDelay;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
LoadTrayIcons();
try
{
LoadConfig();
}
catch (Exception ex)
{
EnableTrayIcon(false); // Dialog box does NOT appear "Modal" to notify icon control!
string sErrMsg = "无法读取程序配置信息!\n\n" + ex.Message;
MessageBox.Show(sErrMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
this.Dispose(true);
throw new Exception("Error occured inside form constructor!"); // internal message
}
// Start tracking device status
tmrChkDev.Interval = 1000;
tmrChkDev.Enabled = true;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.lblBaudrate = new System.Windows.Forms.Label();
this.cboBaudrates = new System.Windows.Forms.ComboBox();
this.chkAutoStartSampling = new System.Windows.Forms.CheckBox();
this.txtStartDelay = new System.Windows.Forms.TextBox();
this.lblSecond1 = new System.Windows.Forms.Label();
this.cboDisplayUnits = new System.Windows.Forms.ComboBox();
this.lblDisplayUnits = new System.Windows.Forms.Label();
this.lblCurrentCounter1 = new System.Windows.Forms.Label();
this.lblCurrentCounter = new System.Windows.Forms.Label();
this.chkValidateCounters = new System.Windows.Forms.CheckBox();
this.lblSecond2 = new System.Windows.Forms.Label();
this.txtValidateInterval = new System.Windows.Forms.TextBox();
this.lblValidateInterval = new System.Windows.Forms.Label();
this.btnModifyCounter = new System.Windows.Forms.Button();
this.lblStartDelay = new System.Windows.Forms.Label();
this.chkDisplayUnitEnabled = new System.Windows.Forms.CheckBox();
this.lblMinValue = new System.Windows.Forms.Label();
this.txtMinValue = new System.Windows.Forms.TextBox();
this.lblMaxValue = new System.Windows.Forms.Label();
this.txtMaxValue = new System.Windows.Forms.TextBox();
this.lblThreshold = new System.Windows.Forms.Label();
this.txtThreshold = new System.Windows.Forms.TextBox();
this.chkLogarithmic = new System.Windows.Forms.CheckBox();
this.lblOperator = new System.Windows.Forms.Label();
this.cboOperators = new System.Windows.Forms.ComboBox();
this.tabMain = new System.Windows.Forms.TabControl();
this.pageGeneral = new System.Windows.Forms.TabPage();
this.lblAvrLogo1 = new System.Windows.Forms.Label();
this.ilAvrLogo = new System.Windows.Forms.ImageList(this.components);
this.lblSeparator1 = new System.Windows.Forms.Label();
this.lblMillisecond1 = new System.Windows.Forms.Label();
this.lblSampleInterval = new System.Windows.Forms.Label();
this.cboSampleIntervals = new System.Windows.Forms.ComboBox();
this.chkStartWithSys = new System.Windows.Forms.CheckBox();
this.chkHideOnStart = new System.Windows.Forms.CheckBox();
this.pageDisplay = new System.Windows.Forms.TabPage();
this.lblAvrLogo2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.pageRun = new System.Windows.Forms.TabPage();
this.cboRefreshIntervals = new System.Windows.Forms.ComboBox();
this.lblMillisecond2 = new System.Windows.Forms.Label();
this.lblRefreshInterval = new System.Windows.Forms.Label();
this.chkTraceData = new System.Windows.Forms.CheckBox();
this.lblDeviceStatus = new System.Windows.Forms.Label();
this.ilDevStatus = new System.Windows.Forms.ImageList(this.components);
this.lvTraceData = new System.Windows.Forms.ListView();
this.chUnitName = new System.Windows.Forms.ColumnHeader();
this.chSampleValue = new System.Windows.Forms.ColumnHeader();
this.chDisplayValue = new System.Windows.Forms.ColumnHeader();
this.chCounter = new System.Windows.Forms.ColumnHeader();
this.ilCntStatus = new System.Windows.Forms.ImageList(this.components);
this.ilTabCtrl = new System.Windows.Forms.ImageList(this.components);
this.tbMain = new System.Windows.Forms.ToolBar();
this.tbbSave = new System.Windows.Forms.ToolBarButton();
this.tbbRun = new System.Windows.Forms.ToolBarButton();
this.tbbAbout = new System.Windows.Forms.ToolBarButton();
this.tbbHelp = new System.Windows.Forms.ToolBarButton();
this.tbbSeparator1 = new System.Windows.Forms.ToolBarButton();
this.tbbHide = new System.Windows.Forms.ToolBarButton();
this.tbbExit = new System.Windows.Forms.ToolBarButton();
this.ilToolbar = new System.Windows.Forms.ImageList(this.components);
this.tmrSample = new System.Windows.Forms.Timer(this.components);
this.tmrTrace = new System.Windows.Forms.Timer(this.components);
this.tmrChkDev = new System.Windows.Forms.Timer(this.components);
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.mnuTray = new System.Windows.Forms.ContextMenu();
this.mnuShowForm = new System.Windows.Forms.MenuItem();
this.mnuMonitor = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.mnuExit = new System.Windows.Forms.MenuItem();
this.tmrValidate = new System.Windows.Forms.Timer(this.components);
this.errorProvider1 = new System.Windows.Forms.ErrorProvider();
this.tmrDelay = new System.Windows.Forms.Timer(this.components);
this.tabMain.SuspendLayout();
this.pageGeneral.SuspendLayout();
this.pageDisplay.SuspendLayout();
this.pageRun.SuspendLayout();
this.SuspendLayout();
//
// lblBaudrate
//
this.lblBaudrate.Location = new System.Drawing.Point(32, 186);
this.lblBaudrate.Name = "lblBaudrate";
this.lblBaudrate.Size = new System.Drawing.Size(72, 16);
this.lblBaudrate.TabIndex = 11;
this.lblBaudrate.Text = "通信波特率";
this.lblBaudrate.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// cboBaudrates
//
this.cboBaudrates.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboBaudrates.Location = new System.Drawing.Point(104, 184);
this.cboBaudrates.Name = "cboBaudrates";
this.cboBaudrates.Size = new System.Drawing.Size(96, 20);
this.cboBaudrates.TabIndex = 12;
//
// chkAutoStartSampling
//
this.chkAutoStartSampling.Location = new System.Drawing.Point(32, 86);
this.chkAutoStartSampling.Name = "chkAutoStartSampling";
this.chkAutoStartSampling.Size = new System.Drawing.Size(184, 20);
this.chkAutoStartSampling.TabIndex = 2;
this.chkAutoStartSampling.Text = "启动后自动打开资源监控";
this.chkAutoStartSampling.CheckedChanged += new System.EventHandler(this.chkAutoStartSampling_CheckedChanged);
//
// txtStartDelay
//
this.txtStartDelay.Enabled = false;
this.txtStartDelay.Location = new System.Drawing.Point(295, 86);
this.txtStartDelay.Name = "txtStartDelay";
this.txtStartDelay.Size = new System.Drawing.Size(32, 21);
this.txtStartDelay.TabIndex = 4;
this.txtStartDelay.Text = "";
this.txtStartDelay.Validating += new System.ComponentModel.CancelEventHandler(this.txtStartDelay_Validating);
//
// lblSecond1
//
this.lblSecond1.Enabled = false;
this.lblSecond1.Location = new System.Drawing.Point(330, 88);
this.lblSecond1.Name = "lblSecond1";
this.lblSecond1.Size = new System.Drawing.Size(24, 16);
this.lblSecond1.TabIndex = 5;
this.lblSecond1.Text = "秒";
this.lblSecond1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// cboDisplayUnits
//
this.cboDisplayUnits.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboDisplayUnits.Location = new System.Drawing.Point(80, 24);
this.cboDisplayUnits.Name = "cboDisplayUnits";
this.cboDisplayUnits.Size = new System.Drawing.Size(88, 20);
this.cboDisplayUnits.TabIndex = 1;
this.cboDisplayUnits.SelectedIndexChanged += new System.EventHandler(this.cboDisplayUnits_SelectedIndexChanged);
//
// lblDisplayUnits
//
this.lblDisplayUnits.Location = new System.Drawing.Point(24, 26);
this.lblDisplayUnits.Name = "lblDisplayUnits";
this.lblDisplayUnits.Size = new System.Drawing.Size(56, 16);
this.lblDisplayUnits.TabIndex = 0;
this.lblDisplayUnits.Text = "显示单元";
//
// lblCurrentCounter1
//
this.lblCurrentCounter1.Enabled = false;
this.lblCurrentCounter1.Location = new System.Drawing.Point(24, 77);
this.lblCurrentCounter1.Name = "lblCurrentCounter1";
this.lblCurrentCounter1.Size = new System.Drawing.Size(80, 16);
this.lblCurrentCounter1.TabIndex = 4;
this.lblCurrentCounter1.Text = "当前计数器:";
//
// lblCurrentCounter
//
this.lblCurrentCounter.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblCurrentCounter.Enabled = false;
this.lblCurrentCounter.Location = new System.Drawing.Point(24, 96);
this.lblCurrentCounter.Name = "lblCurrentCounter";
this.lblCurrentCounter.Size = new System.Drawing.Size(320, 40);
this.lblCurrentCounter.TabIndex = 5;
//
// chkValidateCounters
//
this.chkValidateCounters.Location = new System.Drawing.Point(32, 117);
this.chkValidateCounters.Name = "chkValidateCounters";
this.chkValidateCounters.Size = new System.Drawing.Size(184, 20);
this.chkValidateCounters.TabIndex = 6;
this.chkValidateCounters.Text = "自动检测在用计数器的可用性";
this.chkValidateCounters.CheckedChanged += new System.EventHandler(this.chkValidateCounters_CheckedChanged);
//
// lblSecond2
//
this.lblSecond2.Enabled = false;
this.lblSecond2.Location = new System.Drawing.Point(330, 120);
this.lblSecond2.Name = "lblSecond2";
this.lblSecond2.Size = new System.Drawing.Size(24, 16);
this.lblSecond2.TabIndex = 9;
this.lblSecond2.Text = "秒";
this.lblSecond2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// txtValidateInterval
//
this.txtValidateInterval.Enabled = false;
this.txtValidateInterval.Location = new System.Drawing.Point(295, 118);
this.txtValidateInterval.Name = "txtValidateInterval";
this.txtValidateInterval.Size = new System.Drawing.Size(32, 21);
this.txtValidateInterval.TabIndex = 8;
this.txtValidateInterval.Text = "";
this.txtValidateInterval.Validating += new System.ComponentModel.CancelEventHandler(this.txtValidateInterval_Validating);
//
// lblValidateInterval
//
this.lblValidateInterval.Enabled = false;
this.lblValidateInterval.Location = new System.Drawing.Point(255, 120);
this.lblValidateInterval.Name = "lblValidateInterval";
this.lblValidateInterval.Size = new System.Drawing.Size(40, 16);
this.lblValidateInterval.TabIndex = 7;
this.lblValidateInterval.Text = "间隔";
this.lblValidateInterval.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// btnModifyCounter
//
this.btnModifyCounter.Enabled = false;
this.btnModifyCounter.Location = new System.Drawing.Point(352, 96);
this.btnModifyCounter.Name = "btnModifyCounter";
this.btnModifyCounter.Size = new System.Drawing.Size(80, 24);
this.btnModifyCounter.TabIndex = 6;
this.btnModifyCounter.Text = "更改(&M)...";
this.btnModifyCounter.Click += new System.EventHandler(this.btnModifyCounter_Click);
//
// lblStartDelay
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -