.net - Drag and drop main form to reposition it on the screen, on a different thread or backgroundworker -
i have winforms application , @ times main thread extremely busy. when main thread busy, want user able drag , drop main form (using pbappheader control @ top of form), can reposition main form on screen. since main thread extremely busy @ times, moving main form slow , jerky.
how run following subs on different thread or backgroundworker moving main form smooth? or there better way this?
dim drag boolean dim mousex integer dim mousey integer private sub pbappheader_mousedown(byval sender object, byval e system.windows.forms.mouseeventargs) handles pbappheader.mousedown drag = true 'sets variable drag true. mousex = windows.forms.cursor.position.x - me.left 'sets variable mousex mousey = windows.forms.cursor.position.y - me.top 'sets variable mousey end sub private sub pbappheader_mousemove(byval sender object, byval e system.windows.forms.mouseeventargs) handles pbappheader.mousemove 'if drag set true move form accordingly. if drag me.top = windows.forms.cursor.position.y - mousey me.left = windows.forms.cursor.position.x - mousex end if end sub private sub pbappheader_mouseup(byval sender object, byval e system.windows.forms.mouseeventargs) handles pbappheader.mouseup drag = false 'sets drag false, form not move according code in mousemove end sub
in case runs similar situation, works well.
public const wm_nclbuttondown integer = &ha1 public const ht_caption integer = &h2 private sub pbappheader_mousedown(byval sender object, byval e system.windows.forms.mouseeventargs) handles pbappheader.mousedown if e.button = mousebuttons.left nativemethods.releasecapture() nativemethods.sendmessage(handle, wm_nclbuttondown, ht_caption, 0) end if end sub <comvisible(true)> friend class nativemethods <dllimport("user32.dll", setlasterror:=true, charset:=charset.auto)> _ public shared function sendmessage(byval hwnd intptr, byval msg uinteger, byval wparam intptr, byval lparam intptr) intptr end function <dllimportattribute("user32.dll")> _ public shared function releasecapture() boolean end function end class
Comments
Post a Comment