Hello,

I'm still pretty new at this so all suggestions are much appreciated. When I set the button background image in properties, it looks great. When the button is clicked, the image needs to change. I tried to use an image list like this:

btnSample.BackgroundImage = ImlStimuli.Images.Item(0)

and I tried loading them from a file. I can get them to read, but the image always turns out blurry or distorted. I've tried all variations of alignment, BackgroundImageLayout like stretch/zoom/centered, and I changed flat style, but nothing has worked. Is there a setting or something that I'm missing in properties?

Please help and thanks in advance!

Hello,

I'm still pretty new at this so all suggestions are much appreciated. When I set the button background image in properties, it looks great. When the button is clicked, the image needs to change. I tried to use an image list like this:

btnSample.BackgroundImage = ImlStimuli.Images.Item(0)

and I tried loading them from a file. I can get them to read, but the image always turns out blurry or distorted. I've tried all variations of alignment, BackgroundImageLayout like stretch/zoom/centered, and I changed flat style, but nothing has worked. Is there a setting or something that I'm missing in properties?

Please help and thanks in advance!

Here's the code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Image = System.Drawing.Image.FromFile("someimage.bmp")
    End Sub

Thanks, James, I appreciate your help.

Using this code, if I move the file or email the program to someone who doesn't save it in the same location, will the program not work correctly?

You can always add images to your Application's Resources.
..File Menu / Project / "your application's name" Properties.
....Resources Tab, top Button for "Add Resource", click Drop-Down arrow, select "Add Existing File...", and load your images.

To access them, view the following code sample.
This code is from me adding 2 images to my Resources, "green.png" and "red.png".

Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
        Button1.BackgroundImage = My.Resources.green
    End Sub

    Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
        Button1.BackgroundImage = My.Resources.red
    End Sub

Adding images as a Resource will keep them stored within your Application.

It looks like adding them to Resources will be better, but I added three images to my resources and it only allows me to use one of them. I can see them listed in the Solution Explorer window and I found them in the VB project folder, so I know they are there...

Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.