943,972 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 4189
  • C# RSS
Nov 3rd, 2009
0

close button event for form

Expand Post »
how can i control the close button in a form....
(the three bottons minimize,maxi,close for all windows form)
i hav attached a fig... jst check it...
n pls reply
Attached Thumbnails
Click image for larger version

Name:	untitled.JPG
Views:	90
Size:	20.4 KB
ID:	12442  
Similar Threads
Reputation Points: 8
Solved Threads: 1
Newbie Poster
bk_bhupendra is offline Offline
22 posts
since Oct 2009
Nov 3rd, 2009
2
Re: close button event for form
You can handle the close event on the form using the following event handler:

C# Syntax (Toggle Plain Text)
  1. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  2. {
  3. if (DialogResult.No == MessageBox.Show("Exit without saving changes?", "Data Not Saved", MessageBoxButtons.YesNo))
  4. e.Cancel = true;
  5. }

The above event will be called whenever the Close() method is executed. Use e.Cancel = true to stop the form from being closed.
Last edited by DdoubleD; Nov 3rd, 2009 at 10:37 am.
Reputation Points: 341
Solved Threads: 233
Posting Shark
DdoubleD is offline Offline
984 posts
since Jul 2009
Nov 4th, 2009
0

sry its nt wrking....

Quote ...
Hey its not working...
sud i doudl click smthing jst lik in case of bottons
doubleclicking on that "red cross" results in page load...
Reputation Points: 8
Solved Threads: 1
Newbie Poster
bk_bhupendra is offline Offline
22 posts
since Oct 2009
Nov 4th, 2009
0
Re: close button event for form
Double clicking on a control will create the default event handler. To create handles for other events, got to the properties panel and change to the Events section (lightning bolt at top).
Then double click on the area next to the required event and a basic event handler will be created for you.

Check out the image to see where you ened to click.

Remember to mark the thread as solved if this answered your question.
Attached Thumbnails
Click image for larger version

Name:	eventhandle.png
Views:	1309
Size:	14.0 KB
ID:	12448  
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Ryshad is offline Offline
1,260 posts
since Aug 2009
Nov 5th, 2009
1
Re: close button event for form
You can also add the event handler directly in your form's constructor in the form of:

C# Syntax (Toggle Plain Text)
  1. public Form1()
  2. {
  3. InitializeComponent();
  4. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
  5. }
Reputation Points: 341
Solved Threads: 233
Posting Shark
DdoubleD is offline Offline
984 posts
since Jul 2009
Nov 5th, 2009
0
Re: close button event for form
If you need to customize all 3 of the buttons events, the standard practice is to create a your own title bar control such as seen on AIM and Y! instant messengers.

otherwise, DDoubleD has the right idea.
Reputation Points: 442
Solved Threads: 89
Master Poster
Diamonddrake is offline Offline
721 posts
since Mar 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Returning an array of objects
Next Thread in C# Forum Timeline: How to play Video?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC