Preserve the state of multiple forms

Terrygordon
Terrygordon used Ask the Experts™
on
Hi all

I am designing an application where the user can enter information on different forms that are accessed from a main window. Each form contains a combination of text boxes, radio buttons, etc.

The problem I am having is that if the user closes the form (using the standard X button at the top of the form) and then loads it again from the main window, the form returns to its default values and doesn't save the values that the user entered.

I did consider using tabs instead of separate forms, but there will be situations where the user will want to compare the entries on several forms simultaneously.

So, is it possible (without having to write code to store all the variables and reload them) to save the state of the form when it has been closed and reproduce the user's entries when it is opened again?

P.s. I am quite new to visual studio programming.

Thanks in advance.

Terry
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
What is desired
 
You do not want the user to be able to click on the Close button (the little "x" in the upper right).
 
Method #1: The ControlBox property
 
The WinForm ControlBox property is a good place to start, but it shows or hides the entire control box. That means it either shows or hides all three buttons. That isn't useful because one maywant the minimize and maximize buttons to work or because one may want those buttons to appear for visual consistency.
 
Method #2: Disabling the Close button directly
 
This thread on microsoft.public.dotnet.framework has a solution
 
The result:
- the control box is still visible (min, max, close)
- the close button will appear disabled
- clicking on the close button will not do anything

Save
Top Expert 2011

Commented:
Also:
Use Windows Forms Application Settings to Personalize Your Applications
http://www.devx.com/dotnet/Article/34273/1954
Top Expert 2011

Commented:

And in addition you can use MDI Form for Multiple Document Interface applications
Developing MDI Applications
http://www.c-sharpcorner.com/UploadFile/ggaganesh/DevelopingMDIAppplicationsinCSharp11272005225843PM/DevelopingMDIAppplicationsinCSharp.aspx
 
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Author

Commented:
Hi dj

The "Disabling the Close Button Directly" solution looks like it might work, but you haven't included a link to the thread. Can you post it?

Regards

Terry
Top Expert 2011

Commented:
Most Valuable Expert 2012
Top Expert 2014
Commented:
One option is to allow use to close the form, but intercept the form closing event and just hide it(using form.Hide() method or setting visible = false) and then setting e.cancel = true

Author

Commented:
Hi Codecruiser

This is perfect.....and brilliantly simple. Does exactly what I want.

Regards

Terry

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial