Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I want to write code on minimize button click event in our c# .net windows application.

How can be possible?

Please help me.It's a very urgent for me.

Thanks.

Ankit Agarwal
Software Engineer
Posted
Comments
StM0n 19-Mar-13 3:08am    
Do you want to execute code on minimizing?
Steve44 19-Mar-13 3:09am    
Can you please clarify, if you are using WPF or Windows Forms?
[no name] 19-Mar-13 3:11am    
I am using Windows Form. I want right something on minimize and close button.
[no name] 19-Mar-13 3:12am    
Yes,
I want to execute code on minimize and close button

Try this EDIT May use Resize Event to do it,
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
this.Hide();
}

Then using the FormClosing Event to cancel Close and minimize the Form as below
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
}
}
 
Share this answer
 
Comments
[no name] 19-Mar-13 3:35am    
Dear Rohit,
Resize event successfully running but form closing it's not running.
So, Please help me for form closing button.

Thanks
Steve44 19-Mar-13 3:58am    
How is the closing button not working? Is the application not closing, but continues to run?
To detect the Minimize operation, implement a SizeChanged event handler and check the WindowState property.

For the closing operation, implement an event handler for the Closed event.

In both situations you can invoke your function as required.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900