| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using Core.ONH.Collection.comm;
- namespace Core.ONH.Collection.Receive
- {
- public partial class FrmMain : Form
- {
- public FrmMain()
- {
- InitializeComponent();
- SerialPortHelper.Instance().ShowMessage = ( s) =>
- {
- SafeRefreshControl(txtMessageShow, () =>
- {
- if (txtMessageShow.Text.Length > 10000)
- {
- txtMessageShow.Text = "";
- }
- txtMessageShow.Text = DateTime.Now.ToString("HH:mm:ss") + " " + s + "\r\n" + txtMessageShow.Text;
- });
- };
- }
-
-
- private void msMain_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- switch (e.ClickedItem.Name)
- {
- case "tsmComSetting"://串口设置窗口
- FrmSetting setCom = new FrmSetting();
- setCom.ShowDialog();
- break;
- case "tsmClearData"://数据库连接设置
- txtMessageShow.Text = "";
- break;
- case "tsmExit"://退出
- Close();
-
- break;
- }
- }
- /// <summary>
- /// 安全刷新界面控件 当为子线程时委托刷新界面
- /// </summary>
- /// <param name="control"></param>
- /// <param name="action"></param>
- public void SafeRefreshControl(Control control, Action action)
- {
- if (control.InvokeRequired)
- {
- control.Invoke(action);
- }
- else
- action();
- }
- private void FrmMain_Load(object sender, EventArgs e)
- {
- SerialPortHelper.Instance().InitRecive();
- }
- private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (MessageBox.Show(this, "确认退出系统?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
- DialogResult.Yes)
- {
- SerialPortHelper.Instance().CloseRecive();
- }
- else
- {
- e.Cancel = true;
- }
- }
- private void FrmMain_Resize(object sender, EventArgs e)
- {
- if (this.WindowState == FormWindowState.Minimized)
- {
- this.WindowState = FormWindowState.Minimized;
- this.Visible = false;
- this.notifyIcon1.Visible = true;
- this.notifyIcon1.ShowBalloonTip(2000,"提示","采集软件将在后台运行",ToolTipIcon.Info);
- }
- }
- private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
- {
- notifyIcon1.Visible = false;
- this.ShowInTaskbar = true;
- this.Show();
- this.Activate();
- this.WindowState = FormWindowState.Normal;
- }
-
- }
- }
|