/// <summary>
        /// 窗体关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public virtual void Form_Closing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.MdiFormClosing)
            {
                return;
            }
            else if (e.CloseReason == CloseReason.UserClosing)
            {
                if (DialogResult.OK == MessageBoxPlus.Show(this, "你确定要关闭应用程序吗?", "关闭提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                {
                    //---为保证Application.Exit();时不再弹出提示,所以将FormClosing事件取消
                    this.FormClosing -= new FormClosingEventHandler(this.Form_Closing);

                    //---确认关闭事件
                    e.Cancel = false;

                    //---退出当前窗体
                    this.Dispose();
                }
                else
                {
                    //---取消关闭事件
                    e.Cancel = true;
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// 窗体关闭
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void RFASKFreqCurrentScanForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (e.CloseReason == CloseReason.MdiFormClosing)
     {
         return;
     }
     else if (e.CloseReason == CloseReason.UserClosing)
     {
         if (DialogResult.OK == MessageBoxPlus.Show(this, "你确定要关闭应用程序吗?", "关闭提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
         {
             //---为保证Application.Exit();时不再弹出提示,所以将FormClosing事件取消
             this.FormClosing -= new FormClosingEventHandler(this.RFASKFreqCurrentScanForm_FormClosing);
             //---确认关闭事件
             e.Cancel = false;
             //退出当前应用---如果是MDI窗体,会导致整个应用退出
             //Application.Exit();
             //---退出当前窗体
             this.Dispose();
         }
         else
         {
             //---取消关闭事件
             e.Cancel = true;
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EmbeddedForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            switch (e.CloseReason)
            {
            case CloseReason.None:
                break;

            case CloseReason.WindowsShutDown:
                break;

            case CloseReason.MdiFormClosing:
            case CloseReason.UserClosing:
                if (DialogResult.OK == MessageBoxPlus.Show(this, "你确定要关闭应用程序吗?", "关闭提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                {
                    if (this.IsMdiContainer)
                    {
                        //----为保证Application.Exit();时不再弹出提示,所以将FormClosing事件取消
                        this.FormClosing -= new System.Windows.Forms.FormClosingEventHandler(this.EmbeddedForm_FormClosing);
                    }

                    //---结束进程
                    this.panelPlus_EmbeddedProcess.Stop();

                    //---确认关闭事件
                    e.Cancel = false;

                    //---退出当前窗体
                    this.Dispose();
                }
                else
                {
                    //---取消关闭事件
                    e.Cancel = true;
                }
                break;

            case CloseReason.TaskManagerClosing:
                break;

            case CloseReason.FormOwnerClosing:
                break;

            case CloseReason.ApplicationExitCall:
                break;

            default:
                break;
            }
        }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 public virtual int CloseDevice(string name, RichTextBox msg = null)
 {
     if (this.usedPort != null)
     {
         return(this.usedPort.CloseDevice(name, msg));
     }
     else
     {
         if (this.usedForm != null)
         {
             MessageBoxPlus.Show(this.usedForm, "通信端口初始化失败!\r\n", "错误提示");
         }
         else
         {
             MessageBox.Show("通信端口初始化失败!\r\n", "错误提示");
         }
     }
     return(1);
 }
Beispiel #5
0
        /// <summary>
        /// 事件函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem tsm = (ToolStripMenuItem)sender;

            tsm.Enabled = false;
            switch (tsm.Name)
            {
            //---退出操作
            case "ToolStripMenuItem_Exit":
                //---消息显示
                if (DialogResult.OK == MessageBoxPlus.Show(this, "你确定要关闭应用程序吗?", "关闭提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                {
                    //---退出当前窗体
                    this.Dispose();
                }
                break;

            //---调用计算器
            case "ToolStripMenuItem_Calc":
                ProcessApplication.ActivateRunApplication("calc.exe", "Calculator");
                break;

            //---调用文本编辑器
            case "ToolStripMenuItem_TXT":
                if (ProcessApplication.ActivateRunApplication("notepad++.exe", "Notepad++") == false)
                {
                    ProcessApplication.ActivateRunApplication("notepad.exe", "Notepad");
                }
                break;

            //---调用数字信号源船体
            case "ToolStripMenuItem_GenRF":
                this.DigitalControlRFMenuForm_Init();
                break;

            default:
                break;
            }
            tsm.Enabled = true;
        }
Beispiel #6
0
 /// <summary>
 /// 窗体关闭事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void LabMdiForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     //---判断是Mdi窗体
     if (e.CloseReason == CloseReason.MdiFormClosing)
     {
         if (DialogResult.OK == MessageBoxPlus.Show(this, "你确定要关闭应用程序吗?", "关闭提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
         {
             //----为保证Application.Exit();时不再弹出提示,所以将FormClosing事件取消
             this.FormClosing -= new System.Windows.Forms.FormClosingEventHandler(this.LabMdiForm_FormClosing);
             //---确认关闭事件
             e.Cancel = false;
             //---退出当前窗体
             this.Dispose();
         }
         else
         {
             //---取消关闭事件
             e.Cancel = true;
         }
     }
     //---判断是用户关闭
     else if (e.CloseReason == CloseReason.UserClosing)
     {
         if (DialogResult.OK == MessageBoxPlus.Show(this, "你确定要关闭应用程序吗?", "关闭提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
         {
             //----为保证Application.Exit();时不再弹出提示,所以将FormClosing事件取消
             //this.FormClosing -= new System.Windows.Forms.FormClosingEventHandler(this.LabMdiForm_FormClosing);
             //---确认关闭事件
             e.Cancel = false;
             //---退出当前窗体
             this.Dispose();
         }
         else
         {
             //---取消关闭事件
             e.Cancel = true;
         }
     }
 }
Beispiel #7
0
        /// <summary>
        /// 点击按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public virtual void button_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            btn.Enabled = false;
            switch (btn.Name)
            {
            case "button_initDevice":
                if (btn.Text == "打开端口")
                {
                    if (this.usedPort.OpenDevice(this.comboBox_portName.Text, this.usedMsg) == 0)
                    {
                        this.pictureBox_portState.Tag = 1;
                        btn.Text = "关闭端口";
                        this.pictureBox_portState.Image = Properties.Resources.open;

                        //---控件不使能
                        this.ComboBoxPortInit(false);

                        //---消息显示
                        if (this.usedMsg != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.usedMsg, "端口" + this.comboBox_portName.Text + "打开成功!\r\n", Color.Black, false);
                        }
                    }
                    else
                    {
                        this.pictureBox_portState.Tag   = 2;
                        this.pictureBox_portState.Image = Properties.Resources.error;
                        if (this.usedMsg != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.usedMsg, "端口" + this.comboBox_portName.Text + "端口打开失败!\r\n", Color.Red, false);
                        }
                    }
                }
                else if (btn.Text == "关闭端口")
                {
                    if (this.usedPort != null)
                    {
                        this.pictureBox_portState.Tag = 3;
                        this.usedPort.CloseDevice();
                        btn.Text = "打开端口";
                        this.pictureBox_portState.Image = Properties.Resources.lost;

                        //---控件不使能
                        this.ComboBoxPortInit(true);

                        //---消息显示
                        if (this.usedMsg != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.usedMsg, "端口" + this.comboBox_portName.Text + "关闭成功!\r\n", Color.Black, false);
                        }
                    }
                }
                else
                {
                    if (this.usedForm != null)
                    {
                        MessageBoxPlus.Show(this.usedForm, "端口操作异常!错误操作:" + btn.Text, "错误提示");
                    }
                    else
                    {
                        MessageBox.Show("端口操作异常!错误操作:" + btn.Text, "错误提示");
                    }
                }
                break;

            default:
                break;
            }
            btn.Enabled = true;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public virtual void Button_Click(object sender, System.EventArgs e)
        {
            Button btn = (Button)sender;

            btn.Enabled = false;
            switch (btn.Name)
            {
            case "button_COMMInit":
                if (btn.Text == "打开设备")
                {
                    //if ((this.commPort != null) &&(this.commPort.OpenDevice(this.comboBox_COMMName.Text, this.commRichTextBox) == 0))
                    if ((this.commPort != null) && (this.commPort.OpenDevice(this.m_COMMSerialPortParam, this.commRichTextBox) == 0))
                    {
                        btn.Text = "关闭设备";
                        this.pictureBox_COMMState.Image = Properties.Resources.open;

                        //---消息显示
                        if (this.commRichTextBox != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.commRichTextBox, "设备打开成功!\r\n",
                                                                          Color.Black, false);
                        }

                        this.COMMControl(false);

                        //---加载设备移除处理
                        if (this.commPort.m_OnRemoveDeviceEvent == null)
                        {
                            this.commPort.m_OnRemoveDeviceEvent = this.AddWatcherPortRemove;
                        }
                    }
                    else
                    {
                        this.pictureBox_COMMState.Image = Properties.Resources.error;
                        if (this.commRichTextBox != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.commRichTextBox, "设备打开失败!\r\n",
                                                                          Color.Red, false);
                        }
                    }
                }
                else if (btn.Text == "关闭设备")
                {
                    if (this.commPort != null)
                    {
                        this.commPort.CloseDevice();
                        btn.Text = "打开设备";
                        this.pictureBox_COMMState.Image = Properties.Resources.lost;

                        //---消息显示
                        if (this.commRichTextBox != null)
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.commRichTextBox, "设备关闭成功!\r\n",
                                                                          Color.Black, false);
                        }

                        this.COMMControl(true);
                    }
                }
                else if (btn.Text == "配置设备")
                {
                    //---更新设备配置参数
                }
                else
                {
                    MessageBoxPlus.Show(this.commForm, "设备操作异常!错误操作:" + btn.Text, "错误提示");
                }
                break;

            default:
                break;
            }
            btn.Enabled = true;
        }
Beispiel #9
0
        //========================================================
        #region  钮事件

        /// <summary>
        /// 按钮点击事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Click(object sender, EventArgs e)
        {
            string str = sender.ToString();

            if (str == "清除")
            {
                this.richTextBox_msg.Clear();
            }
            else
            {
                if (this.usedBootLoader == null)
                {
                    MessageBoxPlus.Show(this, "应用发生配置错误,请重新启动!", "错误提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                Button btn = (Button)sender;
                btn.Enabled = false;
                DialogResult dgTemp;
                int          _return = 0;
                //---检查那个按钮使用
                switch (btn.Name)
                {
                case "button_openPort":
                    _return = this.usedBootLoader.OpenDevice(this.comboBox_portName.Text, this.richTextBox_msg);
                    if (_return == 0)
                    {
                        this.button_closePort.Enabled  = true;
                        this.panel_update.Enabled      = true;
                        this.comboBox_portName.Enabled = false;
                        return;
                    }
                    break;

                case "button_closePort":
                    _return = this.usedBootLoader.CloseDevice(this.comboBox_portName.Text, this.richTextBox_msg);
                    if (_return == 0)
                    {
                        this.button_openPort.Enabled   = true;
                        this.panel_update.Enabled      = false;
                        this.comboBox_portName.Enabled = true;
                        return;
                    }
                    break;

                case "button_openFirmware":
                    //---重新初始化打开文件
                    openFirmwareFile = new OpenFileDialog();
                    //---过滤文件
                    openFirmwareFile.AddExtension = true;
                    openFirmwareFile.DefaultExt   = "hex";
                    openFirmwareFile.Filter       = " hex files(*.hex)|*.hex";
                    openFirmwareFile.FilterIndex  = 0;

                    //---获取文件打开的状态
                    dgTemp = openFirmwareFile.ShowDialog();

                    //---判断是否选择固件
                    if (dgTemp == DialogResult.OK)
                    {
                        this.textBox_firmware.Text = openFirmwareFile.FileName;
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.richTextBox_msg, "固件打开成功! \r\n", Color.Black, false);
                    }
                    else if (dgTemp == DialogResult.Cancel)
                    {
                        this.textBox_firmware.Text = string.Empty;
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.richTextBox_msg, "取消固件打开! \r\n", Color.Black, false);
                    }
                    else
                    {
                        this.textBox_firmware.Text = string.Empty;
                        RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.richTextBox_msg, "固件打开失败!\r\n", Color.Red, false);
                    }
                    break;

                case "button_updateFirmware":
                    if ((this.textBox_firmware.Text == null) || (this.textBox_firmware.Text == string.Empty) || (this.openFirmwareFile.SafeFileNames.Length == 0))
                    {
                        //---弹出警告框
                        MessageBoxPlus.Show(this, "固件文件错误,请重新选择!", "错误提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        //---弹出警告框
                        if (DialogResult.OK == MessageBoxPlus.Show(this, "???是否确定更新固件!", "更新提示!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.richTextBox_msg, "取消更新固件!\r\n", Color.Red, false);
                        }
                        else
                        {
                            RichTextBoxPlus.AppendTextInfoTopWithDataTime(this.richTextBox_msg, "准备更新固件!\r\n", Color.Red, false);
                        }
                    }
                    break;

                default:
                    break;
                }
                btn.Enabled = true;
            }
        }