Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Special Commandbuttons (ActiveX, etc).

Status
Not open for further replies.

billschu

Technical User
Apr 3, 2001
38
US
I've noticed that a lot of common applications like MS outlook, Access, etc. have some type of commandbutton or other control that will be highlighted or the picture inside it will change when you mouse over the control. I would like to do something like this for my app but it does not seem possible to do this with the normal commandbutton that is supplied with Access (you can't set the background color, things like that). I'm assuming there is a more sophisticated control that allows you to do this somewhat easily. Right now I am using an image that is kind of acting like a commandbutton; when you run the mouse over it I change the specialeffect property to raised, when I mouse down on it I set the specialeffect property to sunken, etc. This works for the most part but seems like a kludgy way to do it. Also when the mouse leaves the image, it is hard to get another event to be triggered to change the specialeffect back to flat.

Does anyone know a control like this that is available, or maybe a better way to execute this with standard controls that are provided?

Thanks,
Bill
 
The "MS Forms 2.0 Commandbutton" activeX buttons have a BackColor property as well as picture positioning.

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
I use this a lot.
You will need three (3) images. Here I am using img_one, img_two, and img_three.
When all the coding is complete, stack these one on top of the other.

From your Form Load, this initially sets img_one visible and img_two & img_three not visible.
Code:
Private Sub Form_Load()
    Me.img_one.Visible = True
    Me.img_two.Visible = False
    Me.img_three.Visible = False
End Sub

When the mouse is moved over the img_one “button”, image visibility is switched from one to two.
Code:
Private Sub img_one_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.img_one.Visible = False
    Me.img_two.Visible = True
    Me.img_three.Visible = False
End Sub

When you mousedown on img_two, image visibility is switched from two to three.
Code:
Private Sub img_two_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.img_one.Visible = False
    Me.img_two.Visible = False
    Me.img_three.Visible = True
End Sub

When you mouseup on img_two, image visibility is switched from three to two.
Code:
Private Sub img_two_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.img_one.Visible = True
    Me.img_two.Visible = False
    Me.img_three.Visible = False
End Sub

While your mouse is still over the "button" img_two is visible.
By setting the Detail (background) to mousemove and code as below, this will reset the "button" to img_one.
Code:
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.img_one.Visible = True
    Me.img_two.Visible = False
    Me.img_three.Visible = False
End Sub

Hope this helps.


Oak
 
Here's what I do for simple switching:

Private Sub cmdCalc_Click()
On Error GoTo Err_cmdCalc_Click

Dim StrPath1, StrPath2 As String

StrPath1 = "C:\BMPs-GiFs\Calculator.bmp"
StrPath2 = "C:\BMPs-GiFs\AddCode.bmp"

Select Case Me.cmdCalc.Picture

Case StrPath1

Me.cmdCalc.Picture = StrPath2

Case StrPath2

Me.cmdCalc.Picture = StrPath1

End Select

Exit_cmdCalc_Click:
Exit Sub

Err_cmdCalc_Click:
MsgBox Err.Description
Resume Exit_cmdCalc_Click

End Sub
 
I've used images and lablels in place of buttons before, but my biggest gripe is that they don't allow you to abort a click like an actual command button does.

If you press the left button over an image and then slide the mouse off of the image before releasing the button, you'll still get a mouse click event.

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top