473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Panel and MouseEnter / MouseLeave

Hi,

I have a panel on my form.

I want to detect when the user enters my panel with his mouse and when
he leaves my panel.

If the user hovers a control inside my panel, I get the mouseleave,
which is understandable.

But how do I make the MouseLeave event fire only when the user moves the
cursor outside the panel and not when he hovers child controls of the panel?

Thanks in advance!

M O J O

Nov 20 '05 #1
3 7652
Hi Mojo,

Thanks for using Microsoft MSDN Managed Newsgroup. My name is Peter, and I
will be assisting you on this issue.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you do not want the MouseLeave
event was fired when the mouse enter the control on the panel, by default
this will be fired.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think you can derived a cusomized Panel and override the OnMouseMove
event.
Here I write a sample for you.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Panel1 = New MyPanel
Dim textBox1 As New TextBox
Dim label1 As New Label
' Initialize the Panel control.
panel1.Location = New Point(56, 72)
panel1.Size = New Size(264, 152)
' Set the Borderstyle for the Panel to three-dimensional.
panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
' Initialize the Label and TextBox controls.
label1.Location = New Point(16, 16)
label1.Text = "label1"
label1.Size = New Size(104, 16)
textBox1.Location = New Point(16, 32)
textBox1.Text = ""
textBox1.Size = New Size(152, 20)
' Add the Panel control to the form.
Me.Controls.Add(panel1)
' Add the Label and TextBox controls to the Panel.
panel1.Controls.Add(label1)
panel1.Controls.Add(textBox1)
End Sub
Private Sub Panel1_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Panel1.MouseLeave
MsgBox("Mouse Leave")
End Sub
End Class
Public Class MyPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
Dim clientPoint As Point = PointToClient(Cursor.Position)
If Me.DisplayRectangle.Contains(clientPoint) Then
Return
End If
MyBase.OnMouseLeave(e)
End Sub
End Class

Does this answer your question?
If you have any concern on this issue, please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #2
Hi Peter,

Thanks!!!

It was exactly what I was looking for, but couldn't figure it out. :o)

Thanks agan.

M O J O

Peter Huang wrote:
Hi Mojo,

Thanks for using Microsoft MSDN Managed Newsgroup. My name is Peter, and I
will be assisting you on this issue.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you do not want the MouseLeave
event was fired when the mouse enter the control on the panel, by default
this will be fired.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think you can derived a cusomized Panel and override the OnMouseMove
event.
Here I write a sample for you.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Panel1 = New MyPanel
Dim textBox1 As New TextBox
Dim label1 As New Label
' Initialize the Panel control.
panel1.Location = New Point(56, 72)
panel1.Size = New Size(264, 152)
' Set the Borderstyle for the Panel to three-dimensional.
panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
' Initialize the Label and TextBox controls.
label1.Location = New Point(16, 16)
label1.Text = "label1"
label1.Size = New Size(104, 16)
textBox1.Location = New Point(16, 32)
textBox1.Text = ""
textBox1.Size = New Size(152, 20)
' Add the Panel control to the form.
Me.Controls.Add(panel1)
' Add the Label and TextBox controls to the Panel.
panel1.Controls.Add(label1)
panel1.Controls.Add(textBox1)
End Sub
Private Sub Panel1_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Panel1.MouseLeave
MsgBox("Mouse Leave")
End Sub
End Class
Public Class MyPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
Dim clientPoint As Point = PointToClient(Cursor.Position)
If Me.DisplayRectangle.Contains(clientPoint) Then
Return
End If
MyBase.OnMouseLeave(e)
End Sub
End Class

Does this answer your question?
If you have any concern on this issue, please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Nov 20 '05 #3
Cor
Hi Mojo,

The solution from Peter is nice of course, it gives a good method how to
catch the possition of the mouse.

For your question you can also use a switch in the mouseenter en mouseleave
event.
A sample with colors.

\\\
Private Sub Panel1_MouseLeave(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles Panel1.MouseLeave
Me.Panel1.BackColor = Color.Blue
End Sub

Private Sub Panel1_MouseEnter(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles Panel1.MouseEnter
Me.Panel1.BackColor = Color.Red
End Sub
///
I hope this helps a little bit?

Cor

I have a panel on my form.

I want to detect when the user enters my panel with his mouse and when
he leaves my panel.

If the user hovers a control inside my panel, I get the mouseleave,
which is understandable.

But how do I make the MouseLeave event fire only when the user moves the
cursor outside the panel and not when he hovers child controls of the

panel?
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim Mulholland | last post by:
I have written some code that causes mouseover effects on a picture box. The code works fine most of the time and creates some really nice effects. HOWEVER, If i try, i can get the effects to...
3
by: Tim Mulholland | last post by:
i posted this a while ago and never got a response, but i'm still having problems, so i thought i'd see if anyone had any sudden realizations this time Thanks in advance! Tim I have...
1
by: SeaNICK | last post by:
I am trying to figure out how to use MouseEnter or MouseLeave events, and be able to use the EventArgs to determine where the mouse cursor is. To my great confusion, the MouseEnter and MouseLeave...
0
by: Machi | last post by:
I am using C#.NET. API version showintaskbar form Window taskbar hide show not fire events MouseLeave and MouseEnter! Now i am facing a critical problem for MouseLeave and MouseEnter event when i...
0
by: Pucara | last post by:
Hi all, I have noticed that the picturebox object doesnt' fire correctly the mouseEnter mouseLeave events. The problem is seen ONLY when you show a form more than once. You can reproduce it...
0
by: Nathan M | last post by:
Hi, I use a certain control's MouseEnter and MouseLeave events to make this control appear highlighted. The control also has a context menu, but when the control is right-clicked and the...
1
by: Michelangelo | last post by:
Hello, I have a form. On the form is a button. When I move the cursor onto the button, exactly on the edge (most outer pixel of the button), I get a continuous stream of MouseEnter and...
7
by: =?Utf-8?B?Qm9iQWNoZ2lsbA==?= | last post by:
I need to programmatically add an invisible control to my form that will enable me to trigger MouseEnter and MouseLeave code relative to the control area. Is this possible to add the control and...
2
by: kulabhishek | last post by:
Hi! I have a created an extended control that inherits from the Panel class. This functions like an editing pane and allows the user to drag and add controls over it. When I drag the child...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.