Trying to make label display text, wait, then close the program (C#) -
hi have been trying add button program when click button displays text in label, waits user can read it, exits program. if run , try it waits exits without displaying text. sorry if bad explanation got coding. have.
private void button3_click(object sender, eventargs e) { label1.text = "text here"; thread.sleep(500); this.close(); }
call label1.invalidate() force control redrawn. when call thread.sleep, ui thread blocked , not update.
if doesn't work, try label1.refresh() or application.doevents();
private void button3_click(object sender, eventargs e) { label1.text = "text here"; label1.invalidate(); thread.sleep(500); this.close(); } a more ideal solution use timer, thread, or kind of async event run code separately ui:
timer = new timer(); timer.interval = 500; timer.tick += (sender, e) => close(); timer.start(); or
new thread(delegate() { thread.sleep(500); this.close(); }).start(); also note 500 milliseconds pretty short time, did mean 5000 milliseconds, equivalent 5 seconds? may want take @ winforms: application.exit vs enviroment.exit vs form.close, close() closes current window.
Comments
Post a Comment