PDA

View Full Version : حرکت دادن فرم non border



masaioki.ono
جمعه 24 بهمن 1393, 23:18 عصر
من یه فرم ساختم که نان بوردر هست یعنی دکمه های بالایی که شامل بستن و ماکسیمایز و مینیمایز رو برداشتم حالا چطور میتونم فرم رو تکون بدم ؟
سورس پایین رو پیدا کردم اما نتونستم باهاش کار کنم لطفا یکی کمک کنه


I made a label, as a replacement of the Titlebar... and added this code:

Code::::::
Option Explicit
Dim MouseDownX As Long
Dim MouseDownY As Long

Private Sub lblTitleBar_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MouseDownX = X
MouseDownY = Y
End Sub

Private Sub lblTitleBar_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Me.Move Me.Left + X - MouseDownX, Me.Top + Y - MouseDownY
End If
End Sub

setroyd
چهارشنبه 29 بهمن 1393, 13:38 عصر
Dim xx, yy
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
xx = X
yy = Y
End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Me.Top = Me.Top + (Y - yy)
Me.Left = Me.Left + (X - xx)
End If
End Sub


این کد رو جایگزین کن

MortezaZandi
شنبه 16 آبان 1394, 13:15 عصر
سلام
یک روش کلی با استفاده از توابع API هست که در اکثر کاربردها موفق عمل میکنه.

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub ReleaseCapture Lib "User32" ()

Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Public Sub Mover(obj As Object)

On Error Resume Next

Call ReleaseCapture
SendMessage obj.hwnd, &HA1, 2, 0&

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = vbKeyLButton Then Mover Me

End Sub