how do i make the value in text box permanent
-
i am a begineer in c#,and am not getting exact technical terms to explain my problem, though i shall try my best.i have developed a program which takes values from a textbox. its obvious that when i run the program for second time the previously entered values through textbox will get wiped out & textbox will ask for new values. how do i avoid this? how do i make program to run as may times as i want on the values i entered for first time when i ran the program? & only take new values when i change the contents of textbox & continue with this values for any number of times i run the program.
-
i am a begineer in c#,and am not getting exact technical terms to explain my problem, though i shall try my best.i have developed a program which takes values from a textbox. its obvious that when i run the program for second time the previously entered values through textbox will get wiped out & textbox will ask for new values. how do i avoid this? how do i make program to run as may times as i want on the values i entered for first time when i ran the program? & only take new values when i change the contents of textbox & continue with this values for any number of times i run the program.
You need to write the initially entered value to a file or registry someplace. The most commplace is either an INI file or the Registry.
-
You need to write the initially entered value to a file or registry someplace. The most commplace is either an INI file or the Registry.
Not for a .NET application. It's recommended you don't use the registry (for deployment reasons), and even more recommended you don't use INI files (the flat structure is very problematic in this day and age).
Microsoft MVP, Visual C# My Articles
-
i am a begineer in c#,and am not getting exact technical terms to explain my problem, though i shall try my best.i have developed a program which takes values from a textbox. its obvious that when i run the program for second time the previously entered values through textbox will get wiped out & textbox will ask for new values. how do i avoid this? how do i make program to run as may times as i want on the values i entered for first time when i ran the program? & only take new values when i change the contents of textbox & continue with this values for any number of times i run the program.
It's a common practice to actually serialize your controls using XML Serialization to a file. When you instantiate these controls you read your values from that file again. The biggest problem with serialization, though, is that your controls are actually deserialized in their entirety. So the best approach for you is to use an
XmlDocument
orXmlTextWriter
to write these values to an XML file, and read them back in withXmlDocument
orXmlTextReader
. Using XML files is easy in .NET, and there are actually lots of articles here on CodeProject about just what you're asking. You could use the registry (it's strongly recommended you don't use INI files, which are not supported by the .NET FCL (framework class library)), but it's not recommended for deployment reasons. This isn't always such a bad thing if you don't require initial registry values, though. In your case, that would be true. So whether you use an XML file or the registry, just save your text when the form is closed and read them back in when you open your form.Microsoft MVP, Visual C# My Articles
-
Not for a .NET application. It's recommended you don't use the registry (for deployment reasons), and even more recommended you don't use INI files (the flat structure is very problematic in this day and age).
Microsoft MVP, Visual C# My Articles
then what *do* you use? ------------------------------------------------------- ithium is the best. 'Science without religion is lame, religion without science is blind.' --Albert Einstein 'The pioneers of a warless world are the youth who refuse military service.' --Albert Einstein
-
then what *do* you use? ------------------------------------------------------- ithium is the best. 'Science without religion is lame, religion without science is blind.' --Albert Einstein 'The pioneers of a warless world are the youth who refuse military service.' --Albert Einstein
I posted it as a direct reply to the parent thread. .config files are best to target, although writing to them can be dangerous if you don't take errors into account. The registry is an option, but is not recommended because of deployment issues, such as XCOPY deployment.
Microsoft MVP, Visual C# My Articles