【问题标题】:Run executable and show confirmation using C#?使用 C# 运行可执行文件并显示确认?
【发布时间】:2013-03-19 21:47:57
【问题描述】:

我正在编写一些 C# 代码,我想在按下图像时运行一个 .exe。它以这种方式工作正常:

private void pictureBox1_Click(object sender, EventArgs e)
{
    Process.Start("C:\\something.exe");
}

但是,如何添加一条消息,当您单击图像时,会出现一个框询问您是否真的要运行 .exe?

如果有人可以帮助我,那就太好了。谢谢。

【问题讨论】:

    标签: c# executable confirmation


    【解决方案1】:

    您可以通过MessageBox.Show 使用MessageBox

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        if (MessageBox.Show("Are you sure?", "Do you want to start something.exe?", MessageBoxButtons.YesNo) == DialogResult.Yes)
        {
            Process.Start("C:\\something.exe");
        }
    }
    

    【讨论】:

    • @NikolaDavidovic 谢谢 - 已修复。
    【解决方案2】:

    你可以使用简单的MessageBox

    private void pictureBox1_Click(object sender, EventArgs e)
        {
           if(MessageBox.Show("Are you really sure you want to run the program?", "Notification", MessageBoxButtons.OKCancel) == DialogResult.OK)
             Process.Start("C:\\something.exe");
        }
    

    【讨论】:

      【解决方案3】:

      试试这个:

      private void pictureBox1_Click(object sender, EventArgs e)
      {
          if(MessageBox.Show("Are you sure?", "Caption", MessageBoxIcon.Question, MessageBoxButtons.YesNo) == DialogResult.Yes)
          {
              Process.Start("C:\\something.exe");
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-04
        相关资源
        最近更新 更多