📄 form1.cs
字号:
this.lvTraceData.Enabled = false;
this.lvTraceData.FullRowSelect = true;
this.lvTraceData.GridLines = true;
this.lvTraceData.Location = new System.Drawing.Point(16, 77);
this.lvTraceData.Name = "lvTraceData";
this.lvTraceData.Size = new System.Drawing.Size(440, 211);
this.lvTraceData.SmallImageList = this.ilCntStatus;
this.lvTraceData.TabIndex = 5;
this.lvTraceData.View = System.Windows.Forms.View.Details;
//
// chUnitName
//
this.chUnitName.Text = "单元名称";
this.chUnitName.Width = 80;
//
// chSampleValue
//
this.chSampleValue.Text = "采样值";
this.chSampleValue.Width = 90;
//
// chDisplayValue
//
this.chDisplayValue.Text = "显示值";
this.chDisplayValue.Width = 50;
//
// chCounter
//
this.chCounter.Text = "计数器名称";
this.chCounter.Width = 300;
//
// ilCntStatus
//
this.ilCntStatus.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.ilCntStatus.ImageSize = new System.Drawing.Size(16, 16);
this.ilCntStatus.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilCntStatus.ImageStream")));
this.ilCntStatus.TransparentColor = System.Drawing.Color.White;
//
// ilTabCtrl
//
this.ilTabCtrl.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.ilTabCtrl.ImageSize = new System.Drawing.Size(16, 16);
this.ilTabCtrl.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilTabCtrl.ImageStream")));
this.ilTabCtrl.TransparentColor = System.Drawing.Color.White;
//
// tbMain
//
this.tbMain.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.tbMain.AutoSize = false;
this.tbMain.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.tbbSave,
this.tbbRun,
this.tbbAbout,
this.tbbHelp,
this.tbbSeparator1,
this.tbbHide,
this.tbbExit});
this.tbMain.ButtonSize = new System.Drawing.Size(70, 40);
this.tbMain.Divider = false;
this.tbMain.Dock = System.Windows.Forms.DockStyle.Bottom;
this.tbMain.DropDownArrows = true;
this.tbMain.ImageList = this.ilToolbar;
this.tbMain.Location = new System.Drawing.Point(0, 341);
this.tbMain.Name = "tbMain";
this.tbMain.ShowToolTips = true;
this.tbMain.Size = new System.Drawing.Size(496, 40);
this.tbMain.TabIndex = 35;
this.tbMain.TabStop = true;
this.tbMain.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
this.tbMain.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tbMain_ButtonClick);
//
// tbbSave
//
this.tbbSave.ImageIndex = 0;
this.tbbSave.Text = "保存";
this.tbbSave.ToolTipText = "保存设置写入配置文件";
//
// tbbRun
//
this.tbbRun.ImageIndex = 1;
this.tbbRun.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton;
this.tbbRun.Text = "开始";
this.tbbRun.ToolTipText = "启动或停止性能监测";
//
// tbbAbout
//
this.tbbAbout.ImageIndex = 2;
this.tbbAbout.Text = "关于";
this.tbbAbout.ToolTipText = "程序信息";
//
// tbbHelp
//
this.tbbHelp.ImageIndex = 3;
this.tbbHelp.Text = "帮助";
this.tbbHelp.ToolTipText = "打开帮助文档";
//
// tbbSeparator1
//
this.tbbSeparator1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbbHide
//
this.tbbHide.ImageIndex = 4;
this.tbbHide.Text = "隐藏";
this.tbbHide.ToolTipText = "最小化至系统托盘区";
//
// tbbExit
//
this.tbbExit.ImageIndex = 5;
this.tbbExit.Text = "退出";
this.tbbExit.ToolTipText = "退出程序";
//
// ilToolbar
//
this.ilToolbar.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.ilToolbar.ImageSize = new System.Drawing.Size(32, 32);
this.ilToolbar.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilToolbar.ImageStream")));
this.ilToolbar.TransparentColor = System.Drawing.Color.White;
//
// tmrSample
//
this.tmrSample.Interval = 1000;
this.tmrSample.Tick += new System.EventHandler(this.tmrSample_Tick);
//
// tmrTrace
//
this.tmrTrace.Interval = 1000;
this.tmrTrace.Tick += new System.EventHandler(this.tmrTrace_Tick);
//
// tmrChkDev
//
this.tmrChkDev.Interval = 1000;
this.tmrChkDev.Tick += new System.EventHandler(this.tmrChkDev_Tick);
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.mnuTray;
this.notifyIcon1.Text = "超级资源监视器";
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
//
// mnuTray
//
this.mnuTray.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuShowForm,
this.mnuMonitor,
this.menuItem3,
this.mnuExit});
//
// mnuShowForm
//
this.mnuShowForm.Index = 0;
this.mnuShowForm.Text = "主界面 (&S)";
this.mnuShowForm.Click += new System.EventHandler(this.mnuShowForm_Click);
//
// mnuMonitor
//
this.mnuMonitor.Index = 1;
this.mnuMonitor.Text = "监测 (&M)";
this.mnuMonitor.Click += new System.EventHandler(this.mnuMonitor_Click);
//
// menuItem3
//
this.menuItem3.Index = 2;
this.menuItem3.Text = "-";
//
// mnuExit
//
this.mnuExit.Index = 3;
this.mnuExit.Text = "退出 (&X)";
this.mnuExit.Click += new System.EventHandler(this.mnuExit_Click);
//
// tmrValidate
//
this.tmrValidate.Interval = 1000;
this.tmrValidate.Tick += new System.EventHandler(this.tmrValidate_Tick);
//
// tmrDelay
//
this.tmrDelay.Tick += new System.EventHandler(this.tmrDelay_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(496, 381);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tbMain,
this.tabMain});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "超级资源监视器";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.tabMain.ResumeLayout(false);
this.pageGeneral.ResumeLayout(false);
this.pageDisplay.ResumeLayout(false);
this.pageRun.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
// AVR309 library declarations
[DllImport("avr309.dll")]
public static extern int DoSetRS232Baud(int baudrate);
[DllImport("avr309.dll")]
public static extern int DoRS232BufferSend(byte[] buffer , ref int len);
[DllImport("avr309.dll")]
public static extern int DoGetDataPortDirection(ref byte dir);
// Win32 API declarations
[DllImport("shell32.dll", CharSet=CharSet.Unicode, EntryPoint="ShellExecuteW")]
public static extern int ShellExecute(
int hwnd, string lpOperation, string lpFile,
string lpParameters, string lpDirectory, int nShowCmd);
private System.Xml.XmlDocument xmlProfile;
private const string PROFILE_NAME = "Config.Xml";
private string sHelpFilePath;
private DisplayUnit[] displayUnits;
private byte[] packet;
private Icon[] trayIcons;
private bool bTrayIconEnabled = true;
private bool bValidationError = false;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
// Prevent duplicate instance
// ReleaseMutex() must be called on exit
string sMutexName = "Global\\" + typeof(Form1).FullName;
Mutex instanceLock = new Mutex(false,sMutexName);
if (!instanceLock.WaitOne(0, false)) return;
// Set program working directory
Environment.CurrentDirectory = Application.StartupPath;
// Visibility of the main form is
// controlled inside the form constructor
Form1 frmMain = null;
try
{
frmMain = new Form1();
Application.Run(); // Enter message loop
}
catch(Exception ex)
{
// nop
}
finally
{
instanceLock.ReleaseMutex();
}
}
private void EnableTrayIcon(bool enable)
{
// The NotifyIcon control does NOT have an Enabled property, and
// it's a sealed class that can not be inherited. Thus we could NOT
// override the WndProc() of the control to control its behavior.
// Because of the more restrictions on the NotifyIcon control,
// what we could do is to simulate an Enabled status of the control.
if (enable)
{
notifyIcon1.ContextMenu = mnuTray;
bTrayIconEnabled = true;
}
else
{
notifyIcon1.ContextMenu = null;
bTrayIconEnabled = false;
}
}
private void btnModifyCounter_Click(object sender, System.EventArgs e)
{
Form2 frmCounter = new Form2();
if (DialogResult.OK == frmCounter.ShowDialog())
{
// User has selected a counter from the dialog
//
int index = cboDisplayUnits.SelectedIndex;
DisplayUnit du = displayUnits[index];
du.sCatName = frmCounter.CategoryName;
du.sInstName = frmCounter.InstanceName;
du.sCntName = frmCounter.CounterName;
lblCurrentCounter.Text = BuildCounterString(du.sCatName, du.sInstName, du.sCntName);
}
}
private void LoadTrayIcons()
{
trayIcons = new Icon[3];
trayIcons[0] = new Icon(GetType(),"Absent.ico");
trayIcons[1] = new Icon(GetType(),"Normal.ico");
trayIcons[2] = new Icon(GetType(),"Error.ico");
notifyIcon1.Icon = trayIcons[0]; // Initially assuming device in absent state
notifyIcon1.Text = "超级资源监视器 - 当前设备已断开!";
}
private void LoadConfig()
{
XmlNode node = null;
XmlNodeList nodeList = null;
// Load XML profile
xmlProfile = new XmlDocument();
xmlProfile.Load(PROFILE_NAME);
// Load help file path
node = xmlProfile.SelectSingleNode("HyperBarServer/HelpFile");
sHelpFilePath = node.InnerText;
// Load available baudrates
//
nodeList = xmlProfile.SelectNodes("HyperBarServer/BaudrateSettings/Baudrate");
for (int i = 0; i < nodeList.Count; i++)
{
cboBaudrates.Items.Add(nodeList[i].InnerText);
}
node = xmlProfile.SelectSingleNode("HyperBarServer/BaudrateSettings/Default");
cboBaudrates.SelectedIndex = cboBaudrates.FindString(node.InnerText);
// Load available sample intervals
//
nodeList = xmlProfile.SelectNodes("HyperBarServer/SampleIntervalSettings/SampleInterval");
for (int i = 0; i < nodeList.Count; i++)
{
cboSampleIntervals.Items.Add(nodeList[i].InnerText);
}
node = xmlProfile.SelectSingleNode("HyperBarServer/SampleIntervalSettings/Default");
cboSampleIntervals.SelectedIndex = cboSampleIntervals.FindString(node.InnerText);
// Load available refresh intervals (for tracing)
//
nodeList = xmlProfile.SelectNodes("HyperBarServer/RefreshIntervalSettings/RefreshInterval");
for (int i = 0; i < nodeList.Count; i++)
{
cboRefreshIntervals.Items.Add(nodeList[i].InnerText);
}
node = xmlProfile.SelectSingleNode("HyperBarServer/RefreshIntervalSettings/Default");
cboRefreshIntervals.SelectedIndex = cboRefreshIntervals.FindString(node.InnerText);
// Read info for all the display units
//
// Allocate memory for the display units
nodeList = xmlProfile.SelectNodes("HyperBarServer/DisplayUnits/*");
displayUnits = new DisplayUnit[nodeList.Count];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -