Question

I am doing some C# code and I want to run an .exe when pressing an image. Its working fine this way:

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

But, how can I add a message that when you click on the image, a box appears asking if you really want to run the .exe?

It would be great if someone could help me. Thanks.

Was it helpful?

Solution 2

You could use simple 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");
    }

OTHER TIPS

You could use a MessageBox via 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");
    }
}

Try this:

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");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top