I have a Rectangle (the class) that I'm using to define a region on a form and when the mouse enters that region it shows 2 buttons (which are on the form and within the bounds of the rectangle) and I would like the buttons to remain visible when the mouse is over either of the 2 buttons then when the mouse leaves the region or leaves the form they are set to invisible again. Here's the code I have so far:
The problem is when the mouse enters the bounds of the button, the form's MouseLeave event fires and thus my buttons are hidden which means the user can't click either of them either. Any ideas?
VB.NET:
Private m_TitleColor As Color
Private Const m_TitleHeight As Integer = 30I
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Using br As New SolidBrush(m_TitleColor)
e.Graphics.FillRectangle(br, Me.TitleRect())
End Using
End Sub
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
MyBase.OnMouseLeave(e)
Call TitleToggle(False) 'Left the form, hide the buttons
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseMove(e)
Call TitleToggle(Me.TitleRect().Contains(e.Location))
End Sub
Private ReadOnly Property TitleRect() As Rectangle
Get
Return New Rectangle(0I, 0I, Me.ClientSize.Width, m_TitleHeight)
End Get
End Property
Private Sub TitleToggle(ByVal isVisible As Boolean)
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is Button Then ctrl.Visible = isVisible
Next ctrl
End Sub