我正在做一些C#代碼,我想在按圖像時運行一個.exe文件。它的做工精細是這樣的:運行可執行文件並使用C#顯示確認?
private void pictureBox1_Click(object sender, EventArgs e)
{
Process.Start("C:\\something.exe");
}
但是,我怎麼可以添加一條消息,當您單擊圖像上,一個窗口提示,如果你真的想運行.exe?
如果有人能夠幫助我,那將會很棒。謝謝。
我正在做一些C#代碼,我想在按圖像時運行一個.exe文件。它的做工精細是這樣的:運行可執行文件並使用C#顯示確認?
private void pictureBox1_Click(object sender, EventArgs e)
{
Process.Start("C:\\something.exe");
}
但是,我怎麼可以添加一條消息,當您單擊圖像上,一個窗口提示,如果你真的想運行.exe?
如果有人能夠幫助我,那將會很棒。謝謝。
你可以使用簡單的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");
}
你可以使用一個MessageBox
通過MessageBox.Show
:
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");
}
}
試試這個:
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");
}
}
@NikolaDavidovic謝謝 - 固定。 – 2013-03-19 21:59:51