不通過標題欄移動窗體

2022-03-13 20:45:34 字數 1146 閱讀 4879

我們在設計程式時,需要隱藏程式的標題欄,但這樣一來就給我們移動窗體帶來不少的麻煩. 這時,必須要求我們編寫**來實現移動窗體的操作.

以下是我通過用控制項(框)的 mousedown 和 mouseup 事件的組合來實現.

imports system.windows.forms.cursors

public class form1

public x, x1, x2 as integer

public y, y1, y2 as integer

private sub picturebox1_mousedown(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles picturebox1.mousedown

x = me.left

y = me.top

x1 = e.x

y1 = e.y

'當按下滑鼠左鍵時,改變滑鼠游標的形狀

if e.button = windows.forms.mousebuttons.left then

picturebox1.cursor = sizeall

end if

end sub

private sub picturebox1_mouseup(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles picturebox1.mouseup

dim y3, x3 as integer

x2 = e.x

y2 = e.y

' 只有用左鍵才能夠移動窗體

if e.button = windows.forms.mousebuttons.left then

if x2 <> x1 or y2 <> y1 then

x3 = x2 - x1

me.left = x + x3

y3 = y2 - y1

me.top = y + y3

end if

end if

'將滑鼠游標恢復為預設

picturebox1.cursor = [default]

end sub

end class

如何移動無標題欄的窗體

方法一 1.在form1類的標頭檔案中宣告wm nchittest訊息的回應過程函式 public user declarations message void fastcall wmnchittest twmnchittest message begin message map message h...

QT無標題欄加移動窗體

新增幾個成員變數 bool m mousepressed qpoint m mousepos qpoint m windowpos 過載幾個函式 void mousepressevent qmouseevent void mousereleaseevent qmouseevent void mous...

拖動無標題欄窗體

遇到這個問題,解決如下 1.引入命名空間 using system.runtime.interopservices 2.dllimport user32.dll public static extern bool releasecapture dllimport user32.dll public ...