我正在做一些C#代码,我想在按下图像时运行.exe。它的工作方式很好:
private void pictureBox1_Click(object sender, EventArgs e)
{
Process.Start("C:\\something.exe");
}
但是,如何添加一条消息,当您单击图像时,会出现一个框,询问您是否确实要运行.exe?
如果有人可以帮助我会很棒。感谢。
答案 0 :(得分:3)
您可以通过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");
}
}
答案 1 :(得分: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");
}
答案 2 :(得分:1)
试试这个:
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");
}
}