c# - Strange: WinForms form closes automatically after button press -
my app winforms .net 4 (c#) , 1 of forms keeps on closing automatically after pressing button.
- the form have default accept , cancel buttons these not touched.
- there buttontestconnection_click event when clicked, job closes form somehow.
- i using mouse click button not case of cascading keystrokes.
- i not setting dialogresult in function.
i tried check stray this.close / this.dispose calls found none.
here code:
private void buttontestconnection_click (object sender, system.eventargs e) { this.enabled = false; this.cursor = system.windows.forms.cursors.waitcursor; this.progressbar.minimum = 0; this.progressbar.maximum = 500; this.progressbar.value = 0; this.progressbar.visible = true; this.buttontestconnection.visible = false; try { while (this.progressbar.value < this.progressbar.maximum) { // proxy code. this.progressbar.value++; } } catch { } this.progressbar.visible = false; this.buttontestconnection.visible = true; this.progressbar.invalidate(); system.windows.forms.application.doevents(); system.threading.thread.sleep(10); this.cursor = system.windows.forms.cursors.default; this.enabled = true; system.windows.forms.messagebox.show(result.tostring()); }
check if property dialogresult on button equals none.
if not, form closed when hit button , form return setting of button's dialogresult property.
usually, happens lot when copy/paste existing form's button forget remove on pasted button original dialogresult setting
Comments
Post a Comment