Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

override close event

 

How can I override the close event on a child window so that i can cancel it being closed without effecting the parent window?

 

Here's the code i'm using to cancel the close event in my child window:

 

	private void StatusForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
	{
		e.Cancel = true;
	}

 

Here is the code I use to open the child window initially:

 

		StatusForm chStatusForm = new StatusForm();
		chStatusForm.MdiParent = this;
		chStatusForm.Show();

Edited by solus
Can't afford to be neutral on a moving train...
  • *Experts*
Posted

What's wrong with the code you have? It looks perfect...

 

-Ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Guest mutant
Posted

I dont get how to do that too...

Why would they make such a simple thing work like that?

  • *Experts*
Posted

solus, you are currently not overriding the base class method you

mentioned, you just made a subroutine. You need to either:

 

a.) Change the sub name to OnClosing and add the override

keyword, and change the parameters, like this:

private override void OnClosing(System.ComponentModel.CancelEventArgs e)
       {
           e.Cancel = true;
       }

 

or...

b.) Make sure that the current sub is a delegate of the Closing event.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted
I want it so the child window won't close unless the parent window is closed. Both bits of code effects both the child and parent so neither can be closed.
Can't afford to be neutral on a moving train...
  • *Experts*
Posted

In that case, create a boolean variable that can be accessed from

both forms. When the parent form closes, set the boolean value to

true. In the child form, check the value of the boolean variable,

and if it's true then unload the form. You'll also probably want to

set the variable back to false after closing the form.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...