0

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!

3
Contributors
4
Replies
30
Views
6 Years
Discussion Span
Last Post by piratesocrates
0

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
0

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?

0

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.

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.