Windows Develop Bookmark and Share   
 index > Windows Forms General > Form close event stupidity!
 

Form close event stupidity!

Hi,

I'm a PHP developer turned C# and its all a bit confusing.  (i've done a bit of VB6 so maybe it ain't so confusing).

How do i add code to the form close event??

For example, frmMain contains a button to open frmLogin which disables frmMain so the user MUST login.  When frmLogin closes how do i activate the close event to re-instate frmMain.

I tried playing around with frmLogin_closing() {} but i just couldn't work it out.  Please help me

-james

p.s If that didn't make sense, i just want to know how to use the form.close event!
MigrationUser 1  Sunday, February 16, 2003 5:39 PM
just make sure you have an event handler setup for frmLogin_Closing() { } and you should be good to go.


private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("Goodbye!");
}


in the InitializeComponent Method you should also have this.


this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);


If you're using VS.NET all you have to do is select your form and go to the Events list (the little lightening bolt icon) and type in a name for a method to call on the Closing property and it will set all that up for you.
MigrationUser 1  Sunday, February 16, 2003 5:56 PM
cheers, I will try it.  I've tried looking for the event list but can't find it.  Will look l8er when I get home.

Thanx

-james
MigrationUser 1  Monday, February 17, 2003 3:54 AM
if you still can't find it, let us know and we'll help you find it.  It's just at the top of the Properties window (when your form is selected) and looks like a lightening bolt.
MigrationUser 1  Monday, February 17, 2003 1:40 PM
yup, found it.  I was looking for a drop down menu @ the top of the screen like in VB6.

Cheers,
MigrationUser 1  Monday, February 17, 2003 3:27 PM
If you use VB.NET there's a dropdown like in VB6, but C# is different...glad you found it  :) 
MigrationUser 1  Monday, February 17, 2003 3:42 PM

You can use google to search for other answers

Custom Search

More Threads

• catching unhandled exception
• ComboBox column in DataGridView, SelectedValue?
• WHY: datagridview + DataGridViewComboBoxCell on cell (1,1) = exception reentrant call (SetCurrentCellAddressCore function)
• List Box Help
• how to set multiple checklistbox columns
• Tree Grid View data insertions problem
• scroll down - richTextBox
• How do I parse the HTML from a System.Net.HttpWebRequest - w/o using WebBrowser control?
• IShellItemImageFactory increasing GDI leaks
• How to sort a simple bound column in a DataGridView?