2

I would like to save some data from a TextBox. This information is entered by a user.

In my Form_Load event handler I set Button1.Enabled = False and have user input right_serial_code into TextBox1. If the code is correct, Button1 is enabled.

If users puts the correct serial code, it should be persisted in the next session. So that next time the program starts, user does not need to re-enter.

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
james
  • 73
  • 1
  • 9
  • You didn't ask a question. Is there a problem with what you're trying to do, or do you not know how to do it? Please add sample code showing what you've tried. – the Tin Man Dec 03 '12 at 16:35

2 Answers2

2

Go to your project properties page and open the "Settings" tab. Create a new setting called SerialCode. Set the Type to String and set the Scope to either User (so each OS user saves their own serial code) or Application (so all users on the machine share the same serial code).

Then, in the Form_Load event handler, do something like this:

TextBox1.Text = My.Settings.SerialCode

And then in the Button1_Click event handler, so something like this:

My.Settings.SerialCode = TextBox1.Text
Steven Doggart
  • 43,358
  • 8
  • 68
  • 105
0

To recall any piece of information from one program run to another, you need to save it some form of persistent storage.

If the data is small and relevant to the application only, you can save it in the application configuration file. This is an xml file associated with .net applications. See the answer at How can I read/write app.config settings at runtime without using user settings? for instructions on how to save the information. And a more indepth article at http://www.codeproject.com/Articles/14744/Read-Write-App-Config-File-with-NET-2-0.

Community
  • 1
  • 1
Kami
  • 19,134
  • 4
  • 51
  • 63