jeet
jeet

Reputation: 795

C# Updating label with image

I'm learning C# and kind of stuck at this point. I made a form which has a label and a button. When the button is clicked, an image should get loaded on the label and the label resizes to fit the image. However, nothing happens and I don't think any errors are being generated either. What am I missing here? I found the code to resize and load image on MSDN. Here's the code.

private void button1_Click(object sender, EventArgs e)
{
    string ff = "C:\\anImage.png";

    try {
        label1.BackColor = Color.White; //this happens
        Image image1 = Image.FromFile(ff);
        label1.Size = new Size(image1.Width, image1.Height);  //does not happen
        label1.Image = image1; //does not happen
    }
    catch (Exception eee) {
        MessageBox.Show(eee.ToString()); //no messageBox comes up with any errors
    }
}

Upvotes: 1

Views: 123

Answers (1)

GusP
GusP

Reputation: 2475

Try setting label1.AutoSize = false.

Upvotes: 2

Related Questions