Click to See Complete Forum and Search --> : Mousemove


aihsinlee
March 13th, 2001, 09:12 AM
I'm trying to make my own commadButton. I want the button border stays invissible untile the mouse moveover it, and the border disappear when mouse move away. I'm using a pictureBox and four lines around it to make my own button. Under the mousemove event of the pictureBox, I write code to change the line color so the line will appear and it looks like a button. The problem is when I move the mouse away from the pictureBox. the line still there. What should I do to make the line disappear and make the button stays inviable when I move the mouse away.

John G Duffy
March 13th, 2001, 09:28 AM
Use the SetCapture and ReleaseCapture API. Here is a working example. Start a new project. Add a command button to the form. Paste this code into the general declarations section of the form. Run it and move the mouse over the button then away from it. PS. This is not my code. I found it on the Web somewhere. Since you are creating your own control, you may have to finagle with it a bit.

option Explicit

private Declare Function SetCapture Lib "user32" (byval hwnd as Long) as Long
private Declare Function ReleaseCapture Lib "user32" () as Long


'Code:
'Put this code in MouseMove event. In this example, I put a
'CommandButton on a
'form with the name Command1

private Sub Command1_MouseMove(Button as Integer, Shift as Integer, X _
as Single, Y as Single)
static CtrMov as Boolean
static Counter as Long
Counter = Counter + 1
With Command1 'Change this 'Command1' to your control name
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) then
ReleaseCapture
CtrMov = false
Command1.BackColor = &HFF&
Command1.Caption = " Not Over " & Counter
Command1.Refresh
'Put here your code to LostMouseFocus
'for example:
me.print "LostMouseFocus"

else
SetCapture .hwnd
If CtrMov = false then ' do this only once per "over"
CtrMov = true
Command1.BackColor = &HFFFFFF
Command1.Caption = " Over " & Counter
Command1.Refresh
'Put here your code to GetMouseFocus
'for example:
me.print "GetMouseFocus"

End If
End If
End With
End Sub






John G

marciocallejon
May 2nd, 2005, 07:30 AM
Fine your sample Jonh, but you must to specify the conditionals again.

Pluvious
May 2nd, 2005, 01:33 PM
You can also change the lines but putting a mousemove event on the form itself or other nearby objects. In these events you can change the lines back to the color you want. This is easier if you are more new to vb.