• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

How to implement a "MouseOver" function?

I need to know when the mouse move from inside a picbox (whn i use the mousemove event) to outside.
The porblems are that
1) no buttons are pressed, so the picbox don't "capture" mouse moves outside itself
2) I've too many controls around that picbox to write a mousemove event in each to know that the mouse in now outside the picbox, and the form space between all controls are to little to be sure that form detect a mousemove.

So i think i need some API stuffs.. please write some pseudo working code... thanks
0
fcp
Asked:
fcp
1 Solution
 
SethiCommented:
You will have to write the code in MouseMove event of the form also. This is becuase as soon as the mouse moves outside picturebox the mouseevent of the form gets fired. In case there is some other control attached with the picturebox and the form is not visible then write code in Mousemove event of that control.
0
 
SethiCommented:
To shorten the coding effort declare a sub and write the effective code in that sub. Then simply call that sub in MouseMove event of all the controls.
0
 
jgvCommented:
Start a new project, draw a picturebox on the form and add this code:

Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCapture Lib "user32" () As Long

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   
    If X > 0 And X < Picture1.Width And _
       Y > 0 And Y < Picture1.Height Then
       
        If GetCapture <> Picture1.hwnd Then
            Picture1.BackColor = vbRed
            SetCapture Picture1.hwnd
        End If
       
    Else
       
        Picture1.BackColor = Me.BackColor
        ReleaseCapture
   
    End If
   
End Sub
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CuBrCommented:
Nice code, jgv.  Too bad it doesn't work with Images though.
0
 
marconovaroCommented:

Here is an article (and source code) that may help you:

"Generating MouseLeave Events for a Window"
http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/Generating_MouseLeave_Events_for_a_Window/article.asp

HTH
M
0
 
medhaonlineCommented:
Hello fcp,

try doing this.
1.Take a global varibale as boolean.
2.Set default value to false.
3.Whenever mousemoves on the PictureBox, make the variable value to True.
Write the condition as:
if <GlobalVariable> = false then
<GlobalVariable> = true
end if
4.Thus you will get the exact point when the mouse moves over the PictureBox.
5.In the Form_Maousemove, set the variable to false only if it is already true.
Write the condition as:
if <GlobalVariable> = true then
<GlobalVariable> = false
end if
6.Do the same thing in Other Controls' MouseMove.
7.Choose only those controls which are very close to the PictureBox, so that you will not have to write the code,in each and every control's MouseMove event.
8.Doing this, your logic with the other program will remain inract.
9. But I think capturing,both these events should solve your problem.
10.As we have taken a variable, on basic of this you can also code, if required.

All The Best.
0
 
fcpAuthor Commented:
WOW! Very fast. THANKS
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now