Picturebox click event in windows form application
In this article, we will learn how to create a PictureBox control that responds to mouse clicks and sends the coordinates of the clicked point to our code.
The PictureBox is a control that allows you to display images. You can use it to show an image from a file, or as part of an HTML form. You can also use it in Windows Form applications, but for the purposes of this tutorial, we'll be using a Windows Forms application.
First, create a new project in Visual Studio and name it.
You will have a new project and a Form by default.
Use that form and drag the picture box from the toolbox. For further details watch the complete YouTube video.
Same as this create Form2 and add PictureBox.
Now double click on the picture and you have a click event of that Picturebox.
Write code and it will work accordingly.
I'm sharing the code that I've written.
private void pictureBox1_Click(object sender, EventArgs e)
{
// MessageBox.Show("Picture 1 is clicked!");
//int a = 9;
//int b = 90;
//int c = a + b;
//MessageBox.Show("Answer is " +c);
Form2 frm = new Form2();
frm.Show();
this.Hide();
}
Watch the complete video for others, and you will understand all the code.
No comments:
Post a Comment