6
Answers

Closing a Child Form

write2jey

write2jey

20y
11.7k
1
I've a Parent dialog Form which spawns multiple child dialog forms. These child dialog forms execuse the actual core of the program. But when I press "Ok" in the child form, I want the core program to take effect but close the child form. I've tried... form1.Close() but then it fails to execute the core of the program. All I'm doing these days is as soon as "Ok" is pressed, hiding the child dialog. Is hiding a form a normal programing pratice? I mean it's going to exists as long as the life of the parent dialog......but in the background. Is that normal? Is that how all the normal softwares out there work? Hiding all the child dialogs with "form1.Hide" when "Ok" is pressed and then when needed "form1.Show()" a req'd menu/button is invoked?? Thank you, thank you very much. :) JJ
Answers (6)
0
write2jey
NA 69 0 20y
Hey Alan, True... I'm passing a ref. This is how it goes: class Connection : System.Socket { Socket m_Connection; /* object init stuff */ public void Connect(....) { m_Connection.Connect(.....); } } //end of class class ChildForm : System.Windows.Forms.Form { Connect m_NewConnection; /* object init stuff */ //OK Button which establishes a connection private void but_OK (object sender, System.EventArgs e) { m_NewConnection.Connect(....); this.Hide(); //hiding the form.. for temporarily? } } //end of class class ParentForm : System.Windows.Forms.Form { ChildForm m_NewChildForm; Connection m_NewConnection; //****KEY REF. OBJ ******// /* object init stuff */ private void Form_Load (....) { m_NewConnection = mNewChildForm.m_NewConnection; //Getting the reference m_NewChildForm.Show(); //how do i exit this form and keep the connection? } } So as you can probablly figure out that in the Parent form that I'm executing the child Show() method, establish the "connection" and then hiding the child form. So, my original question was, do I've to keep the form on hiding till I've connection on? Users here described that hiding the form is a waste of memory (obviously) so what else can I do? Deactivate it? Or Disable it? Thanks very much Alan. JJ
0
icemanind
NA 22 0 20y
That's wierd....It shouldn't be terminating your connect if you are passing the object back to the parent. I assume you are passing the reference to it back and not the object itself?
0
write2jey
NA 69 0 20y
Hi Alan, Thanks for replying first of all. By "new form" you mean the parent form? I was already doing what you suggested it over here. My childForm is the one which initializes the Socket.Connect(...) method, and I'm returning the reference to my parent form. Then I issue the childForm.Close(). Yet, it still terminates the connection link. So, that's why I'm hiding the child form until the whole TCP connection exists. Say for example, till the transfer of a 50 meg file. Cheers, JJ
0
icemanind
NA 22 0 20y
What you should do, in that case, is to pass the TCPConnection object onto the new form that is displayed, then you can safely issue the childForm1.Close() command. You may have to create a public or internal method in the childForm that simply returns the TCPConnection. They your new form can call the method, get the TCP connection, then you can Close() the childForm Alan
0
write2jey
NA 69 0 20y
Hey Zelda, The thing is, my child form has to be alive because it initiates a TCP connection and establishes a link with a FTP server. So, when I issue the childForm1.Close(), the connection terminates. So, I've to hide the childform through the lifetime of the connection. Is this normal? Your idea reinforced my thoughts. Thanks buddy. Jey
0
zeldafreak
NA 11 0 20y
JJ, I wrote a similiar program not to long ago and that's sort of how I handle it. Of course, it really depends on how you're using these MDI child forms. If you don't plan on using the child form again, you use form1.Close(). Otherwise, you would hide it until it's next use. However, sometimes you may want to close these forms to free up memory. In this case, you would have to do a form1 = new Form(), and then do other initializing before calling form1.Show(). I hope this helps.
Next Recommended Forum