# Visual Basic > Visual Basic 6 and Earlier >  How to Change Picture in Image Button

## halwvtpoman

On my HMI, I have an Image Button.  When the user presses and holds the Image Button, other action is supposed to occur.  When the image Button is released, the other action ceases.  All of this works fine.  

This is a once-working-okay program program that once displayed the  Image Button with a MouseUp picture when the Image Button was not being pressed, and displayed a MouseDown picture as long as the button was pressed.  Due to other changes made to this program, I inadvertantly deleted this MouseUp-MouseDown feature, and I do not recall how it was once implemented.  

My attempted recovery code is the following:

Private Sub ImgDecrOutput_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) 
DecrOutput(Index) = True
forMainDiaplsy.ImgDecrOutput(Index).Picture = "C:/MyProgram/DecrOutput_MouseDown.bmp"
End Sub

Private Sub ImgDecrOutput_MouseUp(Index As Integer, Button As Integer, Shift As Integer,  X As Single, Y As Single)
DecrOutput(Index) = False
forMainDisplay.ImgDecrOutput(Index).Picture = "C:/MyProgram/DecrOutput_MouseUp.bmp"
End Sub

Any help would be appreciated.

Hal W

----------


## SamOscarBrown

Use LoadPicture() 

Ex: forMainDisplay.ImgDecrOutput(Index).Picture = LoadPicture("C:/MyProgram/DecrOutput_MouseUp.bmp")

----------


## halwvtpoman

SamOscarBrown.

Thanks a mil.  But now when I run (still in development mode), I get an error message highlighting LoadPicture.  "Method or Data Member Not Found".

Hal W

----------


## SamOscarBrown

No idea....should work (AFAIK).

Start a NEW project...add a command button, change its Style Property to Graphical

Add this code:



```
Option Explicit
Private Sub command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Command1.Picture = LoadPicture("C:/MyProgram/DecrOutput_MouseDown.bmp")
End Sub


Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Command1.Picture = LoadPicture("C:/MyProgram/DecrOutput_MouseUp.bmp")
End Sub
```

run it, click and hold the mouse, and then release.... and see if you get the same error

----------


## halwvtpoman

I have tried Command Buttons in the past.  I actually have TWO buttons:  One for "IncrOutput"; the other for "DecrOutput".  These buttons should have no interaction with each other.  But if I use Command Buttons, they act in pairs, like start/stop buttons.  That's why I have used Image Buttons, rather than Command Buttons.

BTW, this is an old program, written some 20 years ago.  I has worked for many years just the way I want, but, during the process of upgrading some other feature, I inadvertently deleted the code for the Image Buttons.  And I have forgotten what I had that worked.

Hal W

----------


## SamOscarBrown

Sorry...I have no idea what an "Image Button" is.  

Maybe someone else can advise.

----------


## Ordinary Guy

I thought it was just an Image control being used as a button.

----------


## jdc2000

It sounds like he is using a picture (image) as a button control, and he wants one picture (image) displayed when the button is not being clicked (pressed) and a different picture (image) displayed when the button is being clicked (pressed).

----------


## Ordinary Guy

> I have tried Command Buttons in the past.  I actually have TWO buttons:  One for "IncrOutput"; the other for "DecrOutput".  These buttons should have no interaction with each other.  But if I use Command Buttons, they act in pairs, like start/stop buttons.  
> 
> Hal W


Two Command Buttons, Command1 and Command2, have no interaction with each other. They do not act in pairs. Where did you get the idea that they did.

----------


## SamOscarBrown

He's using an ARRAY of whatever he is using..hence He may be thinking of an ARRAY of buttons....

----------


## SamOscarBrown

> It sounds like he is using a picture (image) as a button control, and he wants one picture (image) displayed when the button is not being clicked (pressed) and a different picture (image) displayed when the button is being clicked (pressed).


Possibly.  Whether he is using a commandbutton, an Image control or a Picturebox control, the 'call' is the same.

For example, an image control (in a 2-day array), the code might look like this:



```
Private Sub image1_MouseDown(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Image1(index).Picture = LoadPicture("C:/MyProgram/DecrOutput_MouseDown.bmp")
End Sub


Private Sub image1_MouseUp(index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Image1(index).Picture = LoadPicture("C:/MyProgram/DecrOutput_MouseUp.bmp")
End Sub
```

----------


## dilettante

Image controls cannot get focus and have no keyboard interaction.  A PictureBox is a better choice for user input.

Are we even sure this is VB5 or VB6 and not Office VBA or VB3 or something?

----------


## Ordinary Guy

If you Google ImageButton you get hits associated with an Android or some kind of Web developing using Java or ASP

----------


## Ordinary Guy

> He's using an ARRAY of whatever he is using..hence He may be thinking of an ARRAY of buttons....


Yeah, I thought of that as a possibility later but did not respond

----------


## SamOscarBrown

Yeah...I had Googled as well.  Also found a C++ thing on it.

----------


## halwvtpoman

> Two Command Buttons, Command1 and Command2, have no interaction with each other. They do not act in pairs. Where did you get the idea that they did.


Sorry.  At the time I wrote that, I had just two command buttons on my HMI, and I noticed that 
when I pressed either one, the visual appearance of the other one changed.  I interpreted that as "interaction between the two".  Later, when I had several command buttons on my HMI, I noticed that the visual appearance of the last command button to be pressed was different.  Why that is, I don;t know, but I was obviously wrong in saying "interaction between the two."

Hal W

----------


## halwvtpoman

I'm using VB6/SP2 on Win 10.

Hal W

----------


## halwvtpoman

I'm using VB6/SP2 on Win 10.

Hal W

----------


## Ordinary Guy

> Sorry.  At the time I wrote that, I had just two command buttons on my HMI, and *I noticed that 
> when I pressed either one, the visual appearance of the other one changed.*  I interpreted that as "interaction between the two".  Later, when I had several command buttons on my HMI, I noticed that the visual appearance of the last command button to be pressed was different.  Why that is, I don;t know, but I was obviously wrong in saying "interaction between the two."
> 
> Hal W


Try setting the TabStops to False

----------


## SamOscarBrown

> Image controls cannot get focus and have no keyboard interaction. A PictureBox is a better choice for user input.


This IS true, but they do react to Mouse Events (which is what OP was discussing).  But I see your point--"better choice" is PB.

----------


## DataMiser

> I noticed that the visual appearance of the last command button to be pressed was different.  Why that is, I don;t know,


 The button you clicked will have focus and that alters the appearance a little so the user knows which button has focus, if any.

----------


## knaepen.ludo

Nieuw project
form met 1 knop
plek deze code onder de knop
en voeg sub btn_click toe

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim btn As New Button
        btn.Width = 175
        btn.Height = 175
        btn.Top = 100
        btn.Left = 50
        btn.Text = "Graag gedaan!"
        btn.TextAlign = ContentAlignment.TopLeft
        btn.BackColor = Color.White
        btn.Image = Image.FromFile("C:\Users\jack_\Pictures\Frituur\kipcorn.jpg").GetThumbnailImage(130, 130, Nothing, IntPtr.Zero)
        Dim lbl As New Label
        lbl.BackColor = Color.White
        lbl.Width = 40
        lbl.Height = 20
        lbl.Left = btn.Width - 55
        lbl.Top = btn.Height - 25
        lbl.AutoSize = False
        lbl.TextAlign = ContentAlignment.BottomRight
        lbl.Text = Trim("5,5")
        btn.Controls.Add(lbl)
        Me.Controls.Add(btn)
        AddHandler btn.Click, AddressOf btn_click
    End Sub
    Private Sub btn_click()
        MsgBox("THX")
    End Sub
End Class

----------


## baka

I would not do like that.
instead just create pictureboxes (hidden) with all the pictures u want to use
that way u dont need to load each time.
now, when u have mouse over an image, just copy from that picturebox.

----------

