Resolved Minimize Windows Form when Clicked Outside the Application

shawnhee

Member
Joined
Dec 2, 2020
Messages
10
Programming Experience
Beginner
I want to minimize my windows form when i clicked anywhere outside it.... But this code will just close the whole program, can anyone help? I want to hide the app to taskbar, and when i press it from taskbar it shows up again.......

Here is the code:
C#:
protected override void OnMouseCaptureChanged(EventArgs e)
{
if (!this.Capture)
{
if (!this.RectangleToScreen(this.DisplayRectangle).Contains(Cursor.Position))
{
this.Hide();
}
else
{
this.Capture = true;
}
}
base.OnMouseCaptureChanged(e);
}

Please help..... Your help is much appreciated
 
Last edited by a moderator:
In the future, please put your code in code tags.

Anyway, of course it looks like your program is closing because you are calling Hide() on line 7. Why would you expect any different behavior? If you want to minimize the window, then set the WindowState to Minimized.
 
I would suggest reading and learning from the WinForms version of Programming Windows by Charles Petzold. It feels like you are missing a lot of the basics about how Windows and WinForms works and you are just Googling your way through to get specific answers without really understanding why those answers were given that way.
 
Solution

Latest posts

Back
Top Bottom