How can i increment a textbox content on form load in such a way that if i run my application and if the form is getting loaded the value should be QS0001 and if i reloa开发者_如何学God the same form by closing my application it should be QS0002.
You can write the value into somewhere other than RAM. For example:
- Registry
- Files(XML or plain text)
- Database
- Application settings
Storing the value into a static variable will not work, because when the application closes, the memory is freed, so the value of the variable will be cleared.
you can do this either using a database or the application settings.
you talk about a field only right now, if you think there will be more fields to behave like that in the future or you have a database for your application anyway, I would do it with the database.
In the form closing event, store the last value of the text box into a static variable.
Implement the form load event, retrieve the value from the static variable and populate the text box with it.
I think the simplest way would be to save the value (in your case QS0001 or whatever) to an xml file. And then the next time when you reload the form read that value to a variable,then perform incrementation process by getting the numerical part and adding 1 to it and then reattaching the resultant value.
精彩评论