c# winform在窗体topmost=true的情况下调用exe

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //窗体
            this.TopMost = true;//将窗体的topmost设为true
            this.Size = new Size(800, 600);
            //panel
            Panel pnl = new Panel();
            pnl.BorderStyle = BorderStyle.FixedSingle;
            pnl.Size = new Size(764, 500);
            pnl.Location = new Point(10, 10);
            this.Controls.Add(pnl);
            //WebBrowser
            WebBrowser wb = new WebBrowser();
            wb.Navigate("http://www.baidu.com");
            wb.Dock = DockStyle.Fill;
            wb.ScrollBarsEnabled = false;
            pnl.Controls.Add(wb);
            //画图
            Button btnMspaint = new Button();
            btnMspaint.Text = "画图";
            btnMspaint.Location = new Point(10, 10 + pnl.Height + 5);
            btnMspaint.Click += new EventHandler(btnMspaint_Click);
            this.Controls.Add(btnMspaint);
        }
        private delegate void MyDelegate();
        /// <summary>
        /// 画图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnMspaint_Click(object sender, EventArgs e)
        {
            ////方法一(缺点:在调用mspaint.exe时主体界面会变得模糊)
            //this.TopMost = false;//将窗体的topmost设为false
            ////启动进程打开电子画笔
            //System.Diagnostics.Process process = new System.Diagnostics.Process();
            //process.StartInfo.FileName = Application.StartupPath + @"\exe\mspaint.exe";
            //process.Start();
            //process.WaitForExit();//等待关闭电子画笔
            //process.Close();//关闭进程
            //this.TopMost = true;//将窗体的topmost设为true
            //方法二(缺点:在调用mspaint.exe时主界面可以被选择并且可以被关闭)
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo.FileName = Application.StartupPath + @"\exe\mspaint.exe";
            process.EnableRaisingEvents = true;
            process.Exited += new EventHandler(process_Exited);
            process.Start();
            this.TopMost = false;
        }
        /// <summary>
        /// 调用委托将窗体的topmost=true
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void process_Exited(object sender, EventArgs e)
        {
            MyDelegate myDelegate = new MyDelegate(SetFormTopMostToTrue);
            this.Invoke(myDelegate);
        }
        private void SetFormTopMostToTrue()
        {
            this.TopMost = true;
        }
    }
}
 
 


你可能感兴趣的:(C#,置顶,调用exe)