PDA

View Full Version : درگ کردن فرم



Netsky
یک شنبه 17 خرداد 1388, 09:33 صبح
سلام .


دوستان چطوری ميشه يه فرم

windows رو که formborderstyle اون none تنظيم شده Dragable کرد يعنی کاربر هرجايه فرم يا يه جايه خاص از اون رو مثلا يکی از کنترل های فرم رو که درگ کرد فرم حرکت کنه.


لطفا اگه ميتونيد کمکم کنيد خيلی عجله دارم

اگه کسی کد بذاره شرمنده میکنه

Tasiyan
یک شنبه 17 خرداد 1388, 09:50 صبح
با اين كد ميتوني با كليدهاي مكان نما فرم رو حركت بدي

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Form1.WindowState = 2 Then Exit Sub
'If Form1 is Maximized, then Stop here and Skip the bottom
'--------------------------------------------------------------------
If KeyCode = vbKeyDown Then
Form1.Top = Form1.Top + 300
End If
'If the Down Arrow Key is pressed, move Form1 an Negative 300 South
'--------------------------------------------------------------------
If KeyCode = vbKeyUp Then
Form1.Top = Form1.Top - 300
End If
'If the Up Arrow Key is pressed, move Form1 an Positive 300 North
'--------------------------------------------------------------------
If KeyCode = vbKeyRight Then
Form1.Left = Form1.Left + 300
End If
'If the Right Arrow Key is pressed, move Form1 an Positive 300 East
'--------------------------------------------------------------------
If KeyCode = vbKeyLeft Then
Form1.Left = Form1.Left - 300
End If
'If the Left Arrow Key is pressed, move Form1 an Negative 300 West
'--------------------------------------------------------------------
End Sub

فعلا اينو داشته باش
:لبخند:

Tasiyan
یک شنبه 17 خرداد 1388, 10:28 صبح
اينم يكي ديگه

Dim xm As Single
Dim ym As Single

Private Sub Command1_Click()
End
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
xm = X
ym = Y
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Form1.Left = Form1.Left + X - xm
Form1.Top = Form1.Top + Y - ym
End If
End Sub

Tasiyan
یک شنبه 17 خرداد 1388, 10:30 صبح
اينم با API

Option Explicit

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" ()

Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Call ReleaseCapture
Call SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End Sub