Picturebox that behaves like a button

I would like to create a user control with a picturebox in it. The picturebox would display an image that behaves like a button when clicked. Does someone know how to do this Would appreciate if you can give me some sample code.

thanks



Answer this question

Picturebox that behaves like a button

  • dev.McClannahan411

    That's very simple. Inside your designer, add the picturebox onto the control, double on the picturebox, VS would generate click event handler. Write your code inside that handler and it would behave as if you clicked on a button. Sample code:

    // pictureBox

    this.pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox.Image")));

    this.pictureBox.Name = "pictureBox";

    this.pictureBox.Click += new System.EventHandler(this.pictureBox1_Click);

    // Handler

    private void pictureBox1_Click(object sender, EventArgs e){

    label1.Text = "You clicked on the picture!!"; }



  • Picturebox that behaves like a button