Hack Forums
[C#] How do i save the text in a textbox? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] How do i save the text in a textbox? (/showthread.php?tid=5525358)

Pages: Pages 1 2


How do i save the text in a textbox? - Mqson - Jan 16, 2017

I have a program that has multiple text boxes, i need it to save the text that is put in the textbox automatically when the program is closed.. I couldnt find a solution anywhere! Hopefully i can find some help <3


* - Annabelle Lee - Jan 16, 2017

What language is this program written in? Typically you'll get the value of the textbox and save it to a file when the program exit functions are called, so it saves, then exits.


* - Mqson - Jan 16, 2017

(Jan 16, 2017 03:08 PM)AnnabelleLee Wrote:  What language is this program written in? Typically you'll get the value of the textbox and save it to a file when the program exit functions are called, so it saves, then exits.

Im so confused, i need some help :/


* - PTSD - Jan 16, 2017

(Jan 16, 2017 03:18 PM)Mqson Wrote:  Im so confused, i need some help :/

We need to know what language the program is being written in before we can even begin to help you.


* - Gt403cyl - Jan 16, 2017

(Jan 16, 2017 03:18 PM)Mqson Wrote:  Im so confused, i need some help :/

Answer the above question.


* - Mqson - Jan 16, 2017

(Jan 16, 2017 03:20 PM)Gt403cyl Wrote:  Answer the above question.
Its in c#
Using vb 2015

This is what i have so far, im completely new to this

gyazo.com/fc3dddef53522c53a525ae7114e9e723

gyazo.com/c50c9823a1091165c4483446fc0454d9


* - Annabelle Lee - Jan 16, 2017

Might want to read through this then: https://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx

It's a nice way to go about it.

Edit: Looking over your code, can you show if you actually MADE the settings? And if so you would simply do something like this:

Code
Properties.Settings.Default.text1 = Textbox1.text; (Basically something like this)
Properties.Settings.Default.Save();

text1 is what I simply assume you're calling your premade property, though it might have a different name.


* - Mqson - Jan 16, 2017

Now im getting this error
CS0103 The name 'textbox1' does not exist in the current context


* - Gt403cyl - Jan 16, 2017

(Jan 16, 2017 03:42 PM)Mqson Wrote:  Now im getting this error
CS0103 The name 'textbox1' does not exist in the current context

What did you name the textbox?
Did you add a textbox?


* - Mqson - Jan 16, 2017

(Jan 16, 2017 03:42 PM)Gt403cyl Wrote:  What did you name the textbox?
Did you add a textbox?

What do you mean


* - Gt403cyl - Jan 16, 2017

(Jan 16, 2017 03:46 PM)Mqson Wrote:  What do you mean

In order to save the contents of the text box you have to have the textbox.

What is the name property of the textbox?


* - Mqson - Jan 16, 2017

(Jan 16, 2017 03:50 PM)Gt403cyl Wrote:  In order to save the contents of the text box you have to have the textbox.

What is the name property of the textbox?

Do you have teamviewer? lol


* - Gt403cyl - Jan 16, 2017

(Jan 16, 2017 03:53 PM)Mqson Wrote:  Do you have teamviewer? lol

Yes but I'm not at home so I can't.

I think you need to take some more time reading before you start making projects.

Have a read here.
https://hackforums.net/showthread.php?tid=5176588


* - Zilog80 - Jan 16, 2017

(Jan 16, 2017 02:28 PM)Mqson Wrote:  I have a program that has multiple text boxes, i need it to save the text that is put in the textbox automatically when the program is closed.. I couldnt find a solution anywhere! Hopefully i can find some help <3

Which are the names of these text boxes?:

Hint:
Select Text box control on your design view form, press F4 and see the content of Name property.


* - iNCEPTiON_V - Jan 16, 2017

You can use JSON, XML , or a normal text file to save data, but since your using visual studio you can use ApplicationSettingsBase.
something like this

Code
Properties.Settings.Default["SomeProperty"] = textBox.Text;
Properties.Settings.Default.Save();

Use the Closing Event of your Form to save before the application Exits.
but i personally would save my data(models) with JSON since its literally 2 lines to Serialize and Deserialize my Data.