Asad
Asad

Reputation: 541

How to save/discard values of controls of a form, upon pressing Ok/Cancel button?

Please guide me as how to save/discard values of controls of a form, upon pressing Ok/Cancel button accordingly in Visual Studio C#?

Controls in a form include TablelayoutPanel(TextBoxes), NumericUpDown.

Need your expert guidance

Regards Asad

Upvotes: 0

Views: 393

Answers (2)

SimoneF
SimoneF

Reputation: 432

The question isn't clear, but in a WinForm you can call

this.Close()  

on the Click event of your Close button.
Every object or variable used by the form will be destroyed. Be careful! running background threads will still be alive until they terminate.

About saving the status of your variables it completely depends on what you need to with them after; you can either keep them in memory and pass them around like parameters or write on a disk (maybe with serialization?).
We need to know more.

edit

You may want to take a look at Application Configuration ( http://msdn.microsoft.com/en-us/library/ms184658(VS.80).aspx ).

Upvotes: 0

Eric
Eric

Reputation: 19873

With both of your buttons, inside the "onclick" event, call a function that will save the content of the form. You also need this call in the "onclose" event of the form, in case the user presses the top-right X button (or not, if you dont want data to be saved at that moment)

Inside that function, you will need some code that will save data to the registry.

Writing in the registry is easy. This webpage also explain how to get the data back. The values you will write will be the textbox.Value and such

Upvotes: 1

Related Questions