Reputation: 479
I have:
Scenario:
I need to add text to the textbox when my mouse is in the scope of my panel or inside the area of the panel and clears the textbox again when not focusing in panel.
I used MouseHover
and MouseLeave
event for this effects. The problem is when I focus on any control inside the panel, the the mouse seems losing the focus in panel and calls MouseLeave
event.
Is there a way to add event when mouse is inside the scope of panel?
Upvotes: 3
Views: 228
Reputation: 16623
You can use the MouseLeave
of your panel and check if your mouse location isn't really into the panel surface.
private void panel_MouseLeave( object sender, EventArgs e ) {
Point mouseposition = this.PointToClient( MousePosition ); // to calculate the mouseposition related to the form (keyword this)
//If the mouse isn't into the panel surface...
if (!(mouseposition.X > panel1.Location.X && mouseposition.Y > panel1.Location.Y && mouseposition.X < panel.Location.X + panel1.ClientSize.Width && mouseposition.Y < panel1.Location.Y + panel.ClientSize.Height) )
textbox.Clear();
}
Upvotes: 4