How to Change a Image on a Button Using Windows Forms

How do I change a image on a Button using Windows Forms?

You will most likely have to change the Button.Image property in the code-behind. See the MSDN Documentation for information and a sample on how to do this.

how to change imagebox with a button | c# windows forms

Add an array of all posible images. Add a variable to store currently loaded image index in this array. And on buttonClick event, change the currently loaded image index, and load the image to picturebox. With this idea, you may have more than 2 images. Something like this:

public partial class Form1 : Form
string[] images = new string[] { "image1.bmp", "image2.bmp", "image3.bmp" };
int currentImageIndex = 0;

private void changebutton_Click(object sender, EventArgs e)
if (currentImageIndex == images.Length)
currentImageIndex = 0;

pictureBox.Image = Image.FromFile(images[currentImageIndex]));

pictureBox image change by clicking a button in win form app

You can call this method each click :

 // it's global var refers to image
int count = 1;

// use count to load the next image
void loadNextPic()
string picPath = "../Pics/imageNum" + count.ToString() + ".jpg";
pictureBox.Image = Image.FromFile(picPath);

Remember you need to name the images as "imageNum1.jpg", "imageNum2.jpg" and so on.

How do I change one image to another upon clicking on a button

You can use a PictureBox and change the image property with your proper image and change a boolean property or variable each time you click on that.

private void pictureBox1_Click(object sender, EventArgs e)
if (flag)
pictureBox1.Image = WindowsFormsApplication21.Properties.Resources.GRAYSCALEsmalltub;
pictureBox1.Image = WindowsFormsApplication21.Properties.Resources.smalltub;

I hope this would solve your problem. Good Luck.

Change button image size in winforms app

You need to resize the Image and then set it as the ButtonsImage:

// where 'MyImage' is the Image to display on the Button
this.Button1.Image = (Image)(new Bitmap(MyImage, new Size(32,32)));

Change button image after clicking it

Jason is right, you should use some kind of temporary storage to save your current bitmap.

The Tag property is useful in this kind of situations. Here a sample code: (Without error handling)

somewhere in your load event

PBr1.Tag = "cb.png";`
PBr1_1.Image = new Bitmap(Path.Combine("Logos\\Images", PBr1.Tag.ToString());

and then in button click

private void PBr1_1_Click(object sender, EventArgs e) 
string imgPath = "Logos\\Images";
PBr1_1.Tag = (PBr1_1.Tag == "cb.png" ? "cg.png") : "cb.png") ;
Bitmap bm = new Bitmap(Path.Combine(imgPath, PBr1.Tag.ToString());
PBr1_1.Image = bm;

Related Topics

Leave a reply