Icon

Gabriell

Newcomer
Joined
Jan 21, 2003
Messages
3
I have made a button ( on a form) with an icon on it. The problem is when I press down the button, the icon was still static (didn't follow the button down). Can you help me please.
Tq...
 
Try This...

Welcome to the forum...

When you set the backgroundimage or image of the button to an image or icon, I can see what you mean...

However, in this case, all we have to do is get a little tricky :cool:

First things first, take the image and make a copy of it. Move the entire copied image down and to the right by 1 or 2 pixels then save it...

Now we setup the trickyness:
* Set the button's background image to (None)
* Add an imagelist1 object to your form
* Add the 2 images to the imagelist1 object
* Set the button's imagelist property to the imagelist1 object
* Set the button's imageindex property to 0 ( zero )

Now for the last step, in the button's Mouse_Down event, put the following code:
Visual Basic:
  Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
    Select Case e.Button
      Case MouseButtons.Left
        Button1.ImageIndex = 1
    End Select
  End Sub

  Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
    Select Case e.Button
      Case MouseButtons.Left
        Button1.ImageIndex = 0
    End Select
  End Sub

If you want to have the same effect for when they use the keyboard to click the button, you'll need to add simular code to the key_down and key_up events...

Try it!!
 
Back
Top