Question

I am trying to show an image within a button using an ImageList, however when I run the code the image is being shown as a tiny 10x10 image. The actual size of the image is 193x261

Here is how I add the image to the list

        ImageList imageList = new ImageList();

        try
        {
            imageList.Images.Add(Image.FromFile(Directory.GetCurrentDirectory() + @"\Images\Phone.png"));
        }
        catch (Exception ex) { MessageBox.Show(ex.ToString()); }

and here is how I add the image to the button

        call.BackgroundImage = imageList.Images[0];
        call.BackgroundImageLayout = ImageLayout.Center;

I forgot to mention, the button is called 'call', the size of the button is 120x110.

Was it helpful?

Solution

Try this:

imageList.ImageSize = new Size(call.Width, call.Height);

It sets the image list size to that of the button (its parent container).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top