c# - ObjectDisposedException when moving form -
i made custom form.
now i'm trying implement feature drag form around while holding titlebar. throws exception:
system.objectdisposedexception
has idea problem is?
this code:
[dllimportattribute("user32.dll")] public static extern int sendmessage(intptr hwnd, int msg, int wparam, int lparam); [dllimportattribute("user32.dll")] public static extern bool releasecapture(); form form; button buttoncancel; button buttonok; dialogresult inputbox(string title, string prompttext, ref string value) { form = new form(); buttoncancel = new button(); buttonok = new button(); label label = new label(); textbox textbox = new textbox(); panel titlebar = new panel(); label lbltitle = new label(); panel pnlexit = new panel(); label lblexit = new label(); form.text = title; label.text = prompttext; textbox.text = value; buttonok.text = "ok"; buttoncancel.text = "cancel"; buttonok.dialogresult = dialogresult.ok; buttoncancel.dialogresult = dialogresult.cancel; label.setbounds(9, 20, 372, 13); textbox.setbounds(12, 36, 372, 20); buttonok.setbounds(228, 72, 75, 23); buttoncancel.setbounds(309, 72, 75, 23); buttoncancel.location = new point(250, 100); buttoncancel.parent = form; buttoncancel.backcolor = colortranslator.fromhtml("#cddc39"); buttoncancel.flatstyle = flatstyle.flat; buttoncancel.flatappearance.bordersize = 0; buttoncancel.mouseclick += buttoncancel_mouseclick; buttonok.location = new point(170, 100); buttonok.parent = form; buttonok.backcolor = colortranslator.fromhtml("#cddc39"); buttonok.flatstyle = flatstyle.flat; buttonok.flatappearance.bordersize = 0; form.height = 150; form.width = 350; form.backcolor = colortranslator.fromhtml("#455a64"); form.formborderstyle = formborderstyle.none; form.autosize = false; form.startposition = formstartposition.centerscreen; form.acceptbutton = buttonok; form.cancelbutton = buttoncancel; titlebar.width = form.width; titlebar.height = 25; titlebar.backcolor = colortranslator.fromhtml("#37474f"); titlebar.parent = form; titlebar.controls.add(pnlexit); titlebar.mousedown += titlebar_mousedown; lblexit.text = "x"; lblexit.font = new font("arial", 9.5f, fontstyle.bold); lblexit.textalign = contentalignment.middlecenter; lblexit.dock = dockstyle.fill; lblexit.mouseclick += lblexit_click; pnlexit.height = titlebar.height - 10; pnlexit.width = 30; pnlexit.backcolor = colortranslator.fromhtml("#cddc39"); pnlexit.location = new point(titlebar.width - 33, 0); pnlexit.parent = titlebar; pnlexit.controls.add(lblexit); lbltitle.parent = titlebar; lbltitle.text = title; lbltitle.forecolor = colortranslator.fromhtml("#cddc39"); lbltitle.font = new font("arial", 9.5f, fontstyle.bold); lbltitle.location = new point(5, 3); label.autosize = true; label.location = new point(25, 50); label.parent = form; label.forecolor = color.white; textbox.parent = form; textbox.location = new point(25, 65); textbox.width = 300; dialogresult dialogresult = form.showdialog(); value = textbox.text; console.writeline("value = " + value); return dialogresult; } private void titlebar_mousedown(object sender, mouseeventargs e) { if (e.button == mousebuttons.left) { releasecapture(); sendmessage(handle, wm_nclbuttondown, ht_caption, 0); } } private void buttoncancel_mouseclick(object sender, mouseeventargs e) { // throw new notimplementedexception(); } private void lblexit_click(object sender, mouseeventargs e) { form.close(); }
Comments
Post a Comment