Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a Windows application.

I create a form, and assign some controls on this form.
This app will allow user to click 'close' button on form to close this form and also allows users to click one dedicated option to re-open this form.

The condition and question now are that :
I've saved the form object before closing this form.
After closing this form, it shows that the form object is disposed, so I can not show this form object again.
I suppose that it should save the form object to a class with 'Serializable' feature, and do serialize/deserialize for this class through a file but, the compiler shows that the Form also need to be set as 'Serializabe'.
So, my questions are :
1. How to set serializable for a form?
2. Can somebody show the full concept step by step?

Thanks.
Posted
Updated 11-Nov-10 23:18pm
v3

1 solution

Wouldn't it be easier to just hide the form instead of really closing it? This would allow you to show it again with all the data on it.

If you want to avoid that the form closes when the user presses the close button "x", then you need to handle the "FormClosing" event:

C#
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
  if (!m_bClose)
  {
    //only hide the form without closing
    this.Hide();
    e.Cancel = true;
  }
  //else: the form is closed
}


This allows you to decide when you want to close the form or just hide it.
 
Share this answer
 
v2
Comments
Sports Kuo 12-Nov-10 5:27am    
Yes, but the conditions are below :
<1> User may click 'close' button on form to close it, so I can not control it to just hide the form. Except that I can grab the FormClosed event to let it do 'hide' but not 'close' the form, can you show it ?
<2> Plus, when user close the app, I have to save all related data, including forms, into file, and after user open the app, I have to read the file to open all forms again, and this also have to solve the same problem, isn't ? Or, is there another way to reach it ? Thanks.
Sports Kuo 12-Nov-10 12:19pm    
Does 'm_bclose' mean the 'close' button be clicked ?
How can I get the 'm_bclose' ? Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900