Click here to Skip to main content
15,921,905 members
Home / Discussions / C#
   

C#

 
GeneralRe: Application shuts down and not just the form Pin
Saamir5-Dec-08 4:07
Saamir5-Dec-08 4:07 
GeneralRe: Application shuts down and not just the form Pin
vlinker5-Dec-08 4:19
vlinker5-Dec-08 4:19 
GeneralRe: Application shuts down and not just the form Pin
Saamir5-Dec-08 4:23
Saamir5-Dec-08 4:23 
GeneralRe: Application shuts down and not just the form Pin
vlinker5-Dec-08 4:46
vlinker5-Dec-08 4:46 
GeneralRe: Application shuts down and not just the form Pin
Saamir5-Dec-08 5:09
Saamir5-Dec-08 5:09 
AnswerRe: Application shuts down and not just the form Pin
DiscoJimmy5-Dec-08 5:32
DiscoJimmy5-Dec-08 5:32 
GeneralRe: Application shuts down and not just the form Pin
Saamir5-Dec-08 6:25
Saamir5-Dec-08 6:25 
GeneralRe: Application shuts down and not just the form Pin
DiscoJimmy5-Dec-08 7:36
DiscoJimmy5-Dec-08 7:36 
If you mean the second method with the events, then yes and no. Yes, events use delegates behind the scenes, but no you don't have to actually declare any delegates yourself.

Just declare an event on the child form using the basic EventHandler class, and then inside the parent form you create an instance of the child form, and subscribe to the event with the += syntax. The parent form then provides an event handler(just like button1_Click) and inside that method you can call Dispose() on the child form. Or set it to null, it's basically the same thing.

on the child form:
public event EventHandler CloseMe;

on the parent form:
ChildForm myChildForm = new ChildForm();<br />
myChildForm.CloseMe += new EventHandler(CloseMethod);<br />


and make sure the child form calls that event when it wants to be shut down.

Of course depending on what you're doing, it would probably be easier to just call this.Close() inside the child form, but then the parent form wouldn't know about it.

I haven't used these inline code blocks before, so hopefully that formats ok.
GeneralRe: Application shuts down and not just the form Pin
Saamir5-Dec-08 7:41
Saamir5-Dec-08 7:41 
GeneralRe: Application shuts down and not just the form Pin
DiscoJimmy5-Dec-08 7:47
DiscoJimmy5-Dec-08 7:47 
QuestionAscii to Hex Conversion [modified] Pin
asquaredtech5-Dec-08 3:47
asquaredtech5-Dec-08 3:47 
GeneralRe: Ascii to Hex Conversion Pin
Luc Pattyn5-Dec-08 4:12
sitebuilderLuc Pattyn5-Dec-08 4:12 
GeneralRe: Ascii to Hex Conversion Pin
asquaredtech5-Dec-08 5:23
asquaredtech5-Dec-08 5:23 
QuestionCreate IE autofill toolbar using C# Pin
jpselvam5-Dec-08 3:00
jpselvam5-Dec-08 3:00 
AnswerRe: Create IE autofill toolbar using C# Pin
Thomas Stockwell5-Dec-08 7:13
professionalThomas Stockwell5-Dec-08 7:13 
GeneralRe: Create IE autofill toolbar using C# Pin
jpselvam5-Dec-08 21:20
jpselvam5-Dec-08 21:20 
Questiondetect window drag Pin
g00fyman5-Dec-08 2:31
g00fyman5-Dec-08 2:31 
AnswerRe: detect window drag Pin
Ravi Bhavnani5-Dec-08 3:03
professionalRavi Bhavnani5-Dec-08 3:03 
GeneralRe: detect window drag Pin
g00fyman5-Dec-08 16:04
g00fyman5-Dec-08 16:04 
Questionsending message to a mobile through the software developed in c#.net by using bluetooth Pin
praveenvkumarv5-Dec-08 2:12
praveenvkumarv5-Dec-08 2:12 
AnswerRe: sending message to a mobile through the software developed in c#.net by using bluetooth Pin
vlinker5-Dec-08 3:20
vlinker5-Dec-08 3:20 
GeneralRe: sending message to a mobile through the software developed in c#.net by using bluetooth Pin
praveenvkumarv5-Dec-08 4:04
praveenvkumarv5-Dec-08 4:04 
GeneralRe: sending message to a mobile through the software developed in c#.net by using bluetooth Pin
vlinker5-Dec-08 4:14
vlinker5-Dec-08 4:14 
Questionprinting a windows form through print preview control in c#.net 2005 Pin
praveenvkumarv5-Dec-08 2:09
praveenvkumarv5-Dec-08 2:09 
AnswerRe: printing a windows form through print preview control in c#.net 2005 [modified] Pin
vlinker5-Dec-08 3:46
vlinker5-Dec-08 3:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.