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;
        }
    }
}
 
 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值