Question Keeping the text value in memory.

ardasipahi01

New member
Joined
Jul 18, 2023
Messages
4
Programming Experience
1-3
Can we keep the textbox.text value in memory until the application is closed? For example, I clicked the button, opened an external form, wrote a test message to textbox1.text in this form, took action, and closed the form. When I enter the same form again, the textbox1.text value will be a test message. But it will be reset when the application is completely closed. without database. Can it be done?
 
Yes it can be done. If you move forward in your development of WinForms and start using a Model-View-Presenter or some other form of Model-View-* design pattern, you keep the data in the model, not in the view. Therefore, as long as the model lives longer than the view, the data is persisted. If the model is only kept in memory, then data you store will on last as long as the program is running. Once the program ends, you lose the data. If you need the data to persist across runs of the program, then you need to save the data from the model someplace else: a file, the database, the registry, a web service, etc.

If you don't want to go that advanced, just keep the data in a static member of the class. But's a hack, as well as tends to go against good object oriented programming practices.
 
Make it possible to reopen the form by hiding it instead of closing it

Or

Use the built in Settings system to write the TextBox value to settings. You can clear the setting on app start
 

Latest posts

Back
Top Bottom