c# - Set default text in textBox on button click -
i'm wondering how set default text in textbox on button click. when users closes form , open again text in textboxes stay. if closes entire app. tried code below, think solution way far working one. thank time.
private void btn_savetext_click(object sender, eventargs e) { this.textbox1.text = textbox1.text; this.textbox2.text = textbox2.text; this.textbox3.text = textbox3.text; this.textbox4.text = textbox4.text; }
it depends default text is?
if going same value each time can set text property in design view, value in textbox each time.
if want textbox save value user has put in, need way store information. possible ways be:
set sql data insert/update procedure, set textbox load saved value sql table each time form loaded.
set xaml, see question guide through that. (this option preferred setting sql data table store 1 value may bit extreme you).
if want sessions advise looking here
from nikita's comment save value .txt document also, again won't preferred thing learn in future. want filewriter or streamwriter. option yours, can either replace file each time, or update existing file add new value.
why code won't work:
this.textbox1.text = textbox1.text; this.textbox2.text = textbox2.text; this.textbox3.text = textbox3.text; this.textbox4.text = textbox4.text;
unfortunately won't save text, , when ui closed/re-opened setting values equal each other, , wouldn't have saved, mean setting them both equal null.
Comments
Post a Comment