winforms - How to continuosly update the textbox in C# -
i have following piece of code:
class notepadclonenomenu : form { protected textbox txtbox; public notepadclonenomenu(string a) { text = "notepad clone no menu"; txtbox = new textbox(); txtbox.parent = this; txtbox.dock = dockstyle.fill; txtbox.borderstyle = borderstyle.none; txtbox.multiline = true; txtbox.scrollbars = scrollbars.both; txtbox.acceptstab = true; txtbox.appendtext(a); txtbox.appendtext("\n"); } } class program1 { public static void main() { string result = "abc"; while(true) { application.run(new notepadclonenomenu(result)); } } }
i want continuously appending string result textbox looks this:
abc abc abc
so on , forth. however, every time called this:
application.run(new notepadclonenomenu(result));
it reset textbox. there anyway can update textbox continuously? new c# quite confusing me.
thanks, phuc pham
first of all, you're continuously closing , opening application. that's why resets. if want run infinite loop, want run inside application proper.
in application code, use event (maybe timer suit you) append text textbox. this:
public someeventontheform (object sender, eventargs e) { txtbox.text += "notepad clone menu"; }
there's 2 more things take account: first, if don't have stoping condition, keep filling memory until run out of it.
second, windows forms run on 1 thread default. you'll using thread update textbox, while it's appending text, form unusable. it'll blank out during event if starts taking long. you'll need second thread handle event if want form usable.
Comments
Post a Comment