using FileManager; using MeasureData; using MeasureThread; using SenseShield; using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; //using SenseShield; using System.Threading.Tasks; using System.Windows.Forms; using static MeasureThread.ThreadStatusEventArgs; namespace HOZProject { public partial class FormHOZMain : Form { #region 控制窗体可以调整大小用 const int HTLEFT = 10; const int HTRIGHT = 11; const int HTTOP = 12; const int HTTOPLEFT = 13; const int HTTOPRIGHT = 14; const int HTBOTTOM = 15; const int HTBOTTOMLEFT = 0x10; const int HTBOTTOMRIGHT = 17; protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x0084: base.WndProc(ref m); Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF); vPoint = PointToClient(vPoint); if (vPoint.X <= 5) if (vPoint.Y <= 5) m.Result = (IntPtr)HTTOPLEFT; else if (vPoint.Y >= ClientSize.Height - 5) m.Result = (IntPtr)HTBOTTOMLEFT; else m.Result = (IntPtr)HTLEFT; else if (vPoint.X >= ClientSize.Width - 5) if (vPoint.Y <= 5) m.Result = (IntPtr)HTTOPRIGHT; else if (vPoint.Y >= ClientSize.Height - 5) m.Result = (IntPtr)HTBOTTOMRIGHT; else m.Result = (IntPtr)HTRIGHT; else if (vPoint.Y <= 5) m.Result = (IntPtr)HTTOP; else if (vPoint.Y >= ClientSize.Height - 5) m.Result = (IntPtr)HTBOTTOM; break; case 0x0201://鼠标左键按下的消息 m.Msg = 0x00A1;//更改消息为非客户区按下鼠标 m.LParam = IntPtr.Zero;//默认值 m.WParam = new IntPtr(2);//鼠标放在标题栏内 base.WndProc(ref m); break; default: base.WndProc(ref m); break; } } #endregion #region 成员变量 private NLog.Logger log; /// /// 控制闪烁 /// public static bool ControlFlicker;//控制流程闪烁 public BackgroundWorker m_BackgroundWorker;// 申明后台对象 /// /// 测量文件 /// public MeasureFile m_MeasureFile; /// 测量线程 public Measure m_Ms; /// /// 显示日志窗体 /// Form m_FormLog = null; /// /// 显示实例化窗体 /// FormMove m_FormInit = null; /// /// 是否已保存 /// public bool IsSave = false; /// /// 初始化用户控件 /// UControl_Init uControl_Init = null; /// /// 日志用户控件 /// UControl_Log ucLog = null; //流程控制 public int m_MeasureType = (int)MeasureMsgManage.measureType.FIB; //是否关闭窗体标识 public bool IsClose = false; OTSMeasureOutputNlog logwin; Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); #endregion #region 构造函数 public FormHOZMain() { InitializeComponent(); //在线程操作过程中,可以设置控件属性 Control.CheckForIllegalCrossThreadCalls = false; m_BackgroundWorker = new BackgroundWorker(); // 实例化后台对象 m_BackgroundWorker.WorkerReportsProgress = true; // 设置可以通告进度 m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消 m_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork); m_BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress); m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork); uControl_Init = new UControl_Init(this); } #endregion #region 测量线程 void DoWork(object sender, DoWorkEventArgs e) { try { m_Ms = new Measure(ConfigurationManager.AppSettings["WebServerIP"].ToString(), ConfigurationManager.AppSettings["WebServerPort"].ToString(), ConfigurationManager.AppSettings["WebServerUrl"].ToString(),m_MeasureFile); m_Ms.InitMeasure(); //注册事件 m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage); //注册事件 m_Ms.SendCutHolesStatus += new CutHolesStatusHandler(displayCutHoleMessage); //自动测量的全过程 m_Ms.DoMeasure(); } catch (Exception ex) { log.Error(ex.ToString(),false); } } public void displayMessage(object sender, ThreadStatusEventArgs e) { //主界面显示内容 this.BeginInvoke((Action)delegate { this.listmsg.Items.Add(e.HoleName +"_" + e.Time.ToString() + "_"+ e.Message + "_" + e.State ); //显示流程中对应编号的内容 MeasureMsgManage.ShowMsgContent(this, e); AddLogListInfo(e); }); } public void displayCutHoleMessage(object sender, CutHolesStatusEventArgs e) { //主界面显示内容 this.BeginInvoke((Action)delegate { //修改切孔状态 ChangeCutHoleState(e.HoleName.ToString(), Convert.ToInt32(e.State)); }); } void UpdateProgress(object sender, ProgressChangedEventArgs e) { } void CompletedWork(object sender, RunWorkerCompletedEventArgs e) { ControlFlicker = false; //设置控件操作 MessageBox.Show("测量已完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); SetWinControlMeasureState(true); pbStop.Visible = false; pbStart.Visible = true; //UControl_ParaInfo uControl_ParaInfo=new UControl_ParaInfo() UControl_ParaInfo uControl_ParaInfo = new UControl_ParaInfo(this); uControl_ParaInfo.pbMeasure.Value = 100; uControl_ParaInfo.lblCompletedAmount.Text = "100%"; } #endregion #region 窗体加载 private void FormHOZMain_Load(object sender, EventArgs e) { try { DogDecrypting.decrypting(100);//参数为许可号 //加载控件的点击事件 this.Click += new EventHandler(FormHOZMain_Click); plFill.Click += new EventHandler(FormHOZMain_Click); plTop.Click += new EventHandler(FormHOZMain_Click); plLeft.Click += new EventHandler(FormHOZMain_Click); plLeftContent.Click += new EventHandler(FormHOZMain_Click); pbImage.Click += new EventHandler(FormHOZMain_Click); //加载窗口移动事件 this.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown); this.plTop.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown); //新建 m_MeasureFile = new MeasureFile(); m_MeasureFile.MParam.GetMeasureParamFromConfigration() ;//读到参数对象中 uControl_Init.DisplayInitialParam();//显示到界面上 logwin = new OTSMeasureOutputNlog(); logwin.Show(); logwin.Height = this.Height; logwin.Left = this.Left - logwin.Width; logwin.Top = this.Top; NLog.Config.LoggingRule lr = NLog.LogManager.Configuration.LoggingRules.FirstOrDefault( r => r.Targets.Any( t => "control" == t.Name ) ); log = NLog.LogManager.GetCurrentClassLogger(); this.Left = this.Location.X + logwin.Width / 2; } catch (Exception ex) { MessageBox.Show(ex.Message, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } } #endregion #region 创建切孔列表信息 /// /// 创建切孔列表信息 /// /// public void CreateCutHoleList(List ListCutHole) { //清空左侧Panel中的切孔控件 ClearPanelControls(); for (int i = ListCutHole.Count - 1; i >= 0; i--) { UControl_CutHole ucCutHole = new UControl_CutHole(this); ucCutHole.Dock = DockStyle.Top; ucCutHole.CutHoleName = ListCutHole[i].HoleName; //显示切孔参数信息 if (ucCutHole.UControl_ParaInfo == null) { ucCutHole.UControl_ParaInfo = new UControl_ParaInfo(this); } plPrarInfo.Width = ucCutHole.UControl_ParaInfo.Width; plPrarInfo.Height = ucCutHole.UControl_ParaInfo.Height; //设置当前样品的参数信息 string CutHoleName = ListCutHole[i].HoleName; ucCutHole.UControl_ParaInfo.Name = CutHoleName; ucCutHole.UControl_ParaInfo.CutHoleName = CutHoleName; ucCutHole.UControl_ParaInfo.Position = ListCutHole[i].Position; ucCutHole.UControl_ParaInfo.StartTime = ListCutHole[i].START.ToString(); ucCutHole.UControl_ParaInfo.EndTime = ListCutHole[i].END.ToString(); int state = (int)ListCutHole[i].STATE; ucCutHole.UControl_ParaInfo.State = state; ucCutHole.UControl_ParaInfo.IsSwitch = ListCutHole[i].SWITCH; ucCutHole.UControl_ParaInfo.ShowParaInfo(); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); plPrarInfo.Controls.Add(ucCutHole.UControl_ParaInfo); plLeftContent.Controls.Add(ucCutHole); ChangeCutHoleState(CutHoleName, state); } plPrarInfo.Visible = false; } #endregion #region 隐藏处理层 //隐藏处理层 private void FormHOZMain_Click(object sender, EventArgs e) { if (plPrarInfo.Visible) { plPrarInfo.Visible = false; } } #endregion #region 设置控件在线程过程中的编辑状态 /// /// 设置控件在线程过程中的编辑状态 /// /// public void SetWinControlMeasureState(bool cState) { pbNew.Enabled = cState; pbOpen.Enabled = cState; pbSave.Enabled = cState; // pbInit.Enabled = cState; pbImportTemplateFile.Enabled = cState; //pbLog.Enabled = cState; pbStart.Enabled = cState; pbStop.Enabled = !cState; //设置切孔是否执行 foreach (Control item in plPrarInfo.Controls) { if (item is UserControl) { UControl_ParaInfo ucParaInfo = (UControl_ParaInfo)item; ucParaInfo.CkIsSwitch.Enabled = cState; } } } #endregion #region 窗体中 线程开始 停止 最大化 最小化 关闭 按钮事件 private void pbMin_MouseEnter(object sender, EventArgs e) { this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_; } private void pbMin_MouseLeave(object sender, EventArgs e) { this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_; } private void pbMax_MouseEnter(object sender, EventArgs e) { this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_; } private void pbMax_MouseLeave(object sender, EventArgs e) { this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_; } private void pbClose_MouseEnter(object sender, EventArgs e) { this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_; } private void pbClose_MouseLeave(object sender, EventArgs e) { this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_; } private void pbStart_MouseEnter(object sender, EventArgs e) { //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.StartMove; } private void pbStart_MouseLeave(object sender, EventArgs e) { //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.Start_3_; } private void pbStop_MouseEnter(object sender, EventArgs e) { //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.StopMove; } private void pbStop_MouseLeave(object sender, EventArgs e) { //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.Stop; } private void pbClose_Click(object sender, EventArgs e) { try { if (m_Ms != null) { if (m_BackgroundWorker.IsBusy) { if (MessageBox.Show("当前测量正在运行,是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //线程停止变量 m_Ms.key_stop = true; IsClose = true; lblStateMessage.Text = "正在关闭窗体...请等待"; pbClose.Enabled = false; ControlFlicker = false; } return; } } if (MessageBox.Show("是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //m_MeasureFile.Save(); this.Close(); } } catch (Exception ex) { log.Error(ex.Message); } } private void pbMin_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } private void pbMax_Click(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Maximized) { this.WindowState = FormWindowState.Normal; } else { this.WindowState = FormWindowState.Maximized; } //窗体据中 this.StartPosition = FormStartPosition.CenterScreen; } #endregion #region 新建、保存、打开、初始化、导入配置、查看日志 private void pbNew_Click(object sender, EventArgs e) { m_MeasureFile.MParam.GetMeasureParamFromConfigration(); } private void pbSave_Click(object sender, EventArgs e) { Saveclick(); } public void Saveclick() { } private void pbOpen_Click(object sender, EventArgs e) { try { //打开默认路径 OpenFileDialog openFileDialog = new OpenFileDialog(); //设置筛选文件格式 openFileDialog.Filter = "测量文件(*.msf)|*.msf"; if (openFileDialog.ShowDialog() == DialogResult.OK) { //读取文件 string measureFileNamePath = openFileDialog.FileName; m_MeasureFile.FileName = measureFileNamePath; m_MeasureFile.Open(); List ListCutHole = m_MeasureFile.ListCutHole; //文件路径 string CutHoleFilePath = m_MeasureFile.CutHoleFilePath; CreateCutHoleList(ListCutHole); ////保存测量文件 //m_MeasureFile.Save(); //设置已保存状态 IsSave = true; } } catch (Exception ex) { log.Error(ex.Message); } } private void pbInit_Click(object sender, EventArgs e) { if (uControl_Init == null) { uControl_Init = new UControl_Init(this); //uControl_Init.ReloadConfig(); } if (m_FormInit == null) { m_FormInit = new FormMove(); } m_FormInit.StartPosition = FormStartPosition.CenterScreen; m_FormInit.FormBorderStyle = FormBorderStyle.None; m_FormInit.Width = uControl_Init.Width + 8; m_FormInit.Height = uControl_Init.Height + 8; if (m_FormInit.Controls.Count == 0) { uControl_Init.Location = new Point(4,4); m_FormInit.Controls.Add(uControl_Init); } m_FormInit.ShowDialog(); //ConfigurationParameter(); m_FormInit.Left = this.Left; } private void pictureBox1_Click(object sender, EventArgs e) { } private void pbImportTemplateFile_Click(object sender, EventArgs e) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString(); //判断保存的路径是否存在 if (!Directory.Exists(m_TemplateFilePath)) { ////创建路径 //Directory.CreateDirectory(m_TemplateFilePath); FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径"; //dialog.RootFolder = Environment.SpecialFolder.Programs; if (dialog.ShowDialog() == DialogResult.OK) { m_TemplateFilePath = dialog.SelectedPath; config.AppSettings.Settings["TemplateFilePath"].Value = m_TemplateFilePath; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件 } } //打开默认路径 OpenFileDialog openFileDialog = new OpenFileDialog(); //设置默认打开路径(绝对路径) openFileDialog.InitialDirectory = m_TemplateFilePath; openFileDialog.Filter = "样品参数文件|*.cfg"; if (openFileDialog.ShowDialog() == DialogResult.OK) { if (uControl_Init == null) { uControl_Init = new UControl_Init(this); } //设置选择的模板文件 uControl_Init.ReadConfigPath = openFileDialog.FileName; //获取文件 uControl_Init.ReadConfigInfo(); } } private void pbLog_Click(object sender, EventArgs e) { } //显示日志 private void AddLogListInfo(ThreadStatusEventArgs e) { if (m_FormLog != null) { foreach (Control item in m_FormLog.Controls) { if (item is UserControl) { if (item.Name == "UControl_Log") { ucLog = (UControl_Log)item; //获取日志信息 if (listmsg.Items.Count > 0) { string[] strLog = new string[listmsg.Items.Count]; for (int i = 0; i < listmsg.Items.Count; i++) { //赋值给数组 strLog[i] = listmsg.Items[i].ToString(); } ucLog.ShowProcessLogInfo(strLog); } } } } } } #endregion #region 修改切孔状态 /// /// 修改切孔状态 /// /// /// public void ChangeCutHoleState(string CutHoleName, int States) { foreach (Control item in plLeftContent.Controls) { if (item is UserControl) { UControl_CutHole cutHole = (UControl_CutHole)item; if (cutHole.CutHoleName == CutHoleName) { Button btnCutHole = (Button)cutHole.Controls.Find("btnCutHole", false)[0]; switch (States) { //运行中 case (int)MeasureThread.ThreadState.InProcess: //btnCutHole.BackColor = Color.Yellow; btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_; btnCutHole.BackgroundImageLayout = ImageLayout.Center; ChangeCutHoleMeasureState(CutHoleName, States); ControlFlicker = true; break; //等待 case (int)MeasureThread.ThreadState.Waiting: //btnCutHole.BackColor = Color.Yellow; btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_; btnCutHole.BackgroundImageLayout = ImageLayout.Center; ChangeCutHoleMeasureState(CutHoleName, States); break; //准备 case (int)MeasureThread.ThreadState.Ready: //btnCutHole.BackColor = Color.White; btnCutHole.BackgroundImage = Properties.Resources.CutHole_Gray_2_; btnCutHole.BackgroundImageLayout = ImageLayout.Center; ChangeCutHoleMeasureState(CutHoleName, States); break; //失败 case (int)MeasureThread.ThreadState.Failed: //btnCutHole.BackColor = Color.Red; btnCutHole.BackgroundImage = Properties.Resources.CutHole_Red_2_; btnCutHole.BackgroundImageLayout = ImageLayout.Center; ChangeCutHoleMeasureState(CutHoleName, States); ControlFlicker = false; break; //完成 case (int)MeasureThread.ThreadState.Success: //btnCutHole.BackColor = Color.GreenYellow; btnCutHole.BackgroundImage = Properties.Resources.CutHole_Green_2_; btnCutHole.BackgroundImageLayout = ImageLayout.Center; //修改切孔状态 ChangeCutHoleMeasureState(CutHoleName, States); ControlFlicker = false; break; } break; } } } } #endregion #region 修改切孔状态 public void ChangeCutHoleMeasureState(string CutHoleName, int States) { if (plPrarInfo.Controls.Count > 0) { foreach (Control item in plPrarInfo.Controls) { if (item is UserControl) { if (item.Name == CutHoleName) { UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item; //获取切孔列表 List aCutHole = m_MeasureFile.ListCutHole; foreach (CutHole cutHoleItem in aCutHole) { if (cutHoleItem.HoleName == CutHoleName) { //设置开始时间与结束时间 uControl_ParaInfo.StartTime = cutHoleItem.START.ToString(); uControl_ParaInfo.EndTime = cutHoleItem.END.ToString(); uControl_ParaInfo.ShowTime(); break; } } switch (States) { //准备 case (int)MeasureThread.ThreadState.Ready: //修改切孔状态 uControl_ParaInfo.lblShowState.Text = "准备"; break; //等待 case (int)MeasureThread.ThreadState.Waiting: //修改切孔状态 uControl_ParaInfo.lblShowState.Text = "等待"; break; //进行中 case (int)MeasureThread.ThreadState.InProcess: //修改切孔状态 uControl_ParaInfo.lblShowState.Text = "进行中"; break; //完成 case (int)MeasureThread.ThreadState.Success: //修改切孔状态 uControl_ParaInfo.lblShowState.Text = "完成"; break; //失败 case (int)MeasureThread.ThreadState.Failed: uControl_ParaInfo.lblShowState.Text = "失败"; uControl_ParaInfo.pbMeasure.Value = 100; uControl_ParaInfo.lblCompletedAmount.Text = "100%"; break; } break; } } } } } #endregion #region 拖动无窗体的控件 [DllImport("user32.dll")]//拖动无窗体的控件 public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); public const int WM_SYSCOMMAND = 0x0112; public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002; private void FormHOZMain_MouseDown(object sender, MouseEventArgs e) { if (this.WindowState == FormWindowState.Normal) { //拖动窗体 ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } } #endregion #region 开始、结束线程事件 private void pbStart_Click(object sender, EventArgs e) { if (plLeftContent.Controls.Count==0) { MessageBox.Show("请添加切孔信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (IsSave) { if (m_BackgroundWorker.IsBusy) { MessageBox.Show("线程已经运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { log.Info("开始", true); m_BackgroundWorker.RunWorkerAsync(this); //设置控件操作 SetWinControlMeasureState(false); pbStop.Visible = true; pbStart.Visible = false; } } else { MessageBox.Show("请保存当前测量文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } private void pbStop_Click(object sender, EventArgs e) { if (m_Ms != null) { if (MessageBox.Show("是否停止当前测量?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes) { ControlFlicker = false; //线程停止变量 m_Ms.key_stop = true; } } } #endregion #region 清空内容容器中的控件 /// /// 清空内容容器中的控件 /// private void ClearPanelControls() { //清空内容容器中的控件 plLeftContent.Controls.Clear(); plPrarInfo.Controls.Clear(); } /// /// 清空日志控件内容 /// private void ClearContrlsContent() { try { if (ucLog != null) { if (ucLog.dgvLog != null) { if (ucLog.dgvLog.Rows.Count > 0) { ucLog.dgvLog.Rows.Clear(); } } } if (listmsg != null) { if (listmsg.Items.Count > 0) { listmsg.Items.Clear(); } } } catch (Exception ex) { log.Error(ex.Message); } } #endregion #region 测试修改切孔中流程状态 private void button1_Click(object sender, EventArgs e) { if (plPrarInfo.Controls.Count > 0) { string name = textBox1.Text; string code = textBox2.Text; bool state = Convert.ToBoolean(comboBox1.Text); foreach (Control item in plPrarInfo.Controls) { if (item is UserControl) { if (item.Name == name) { UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item; TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem; foreach (TimeLineItem tlItem in ParaItem) { if (tlItem.Code == code) { tlItem.State = Convert.ToInt32(state); break; } } uControl_ParaInfo.TimeLineInvalidate(); break; } } } } } #endregion private void FormHOZMain_Resize(object sender, EventArgs e) { plMain.Left = 2; plMain.Top = 2; plMain.Width = this.Width - 4; plMain.Height = this.Height - 4; plFill.Width = plMain.Width - plLeft.Width - 4; plFill.Height = plMain.Height - plTop.Height - 4; plFill.Left = plLeft.Width + 4; plFill.Top = plTop.Height + 4; if(this.WindowState!= FormWindowState.Maximized) { plPrarInfo.Height = 505; foreach (Control item in plPrarInfo.Controls) { if (item is UserControl) { if(item.Height>505) { item.Height = 505; } } } } } private void FormHOZMain_Paint(object sender, PaintEventArgs e) { } private void FormHOZMain_FormClosing(object sender, FormClosingEventArgs e) { if (m_Ms != null) { if (m_Ms.iExtender != null) { m_Ms.iExtender.CloseExtender(); } } } private void FormHOZMain_LocationChanged(object sender, EventArgs e) { if (logwin != null) { logwin.Left = this.Left-logwin.Width; logwin.Top = this.Top; } } private void pbPause_Click(object sender, EventArgs e) { if (File.Exists(m_MeasureFile.m_SavePath)) { string position = System.Environment.CurrentDirectory; //Process pro = Process.Start(@"C:\Users\admin\Desktop\Report\Report\ExportReport.exe", @"C:\Users\admin\Downloads\3\3\3.msf");//打开程序B Process pro = Process.Start(position + "\\Report\\ExportReport.exe", m_MeasureFile.m_SavePath);//打开程序B pro.WaitForExit(); int Result = pro.ExitCode;//程序B退出回传值 if (Result == 1)//接收到程序B退出代码"1" { MessageBox.Show("退出程序B"); } } else { MessageBox.Show("尚未保存文件"); } } } }