View Full Version : حرکت دادن فرم های none
M.KH-SH
سه شنبه 22 آذر 1390, 19:03 عصر
سلام
خسته نباشین
یک سئوال :
یک فرم none رو چطور میشه در صفحه نمایش جابجا کرد.
البته این قسمت جابجایی تنها از با کلیک کردن و نگه داشتن از روی MenuStrip امکان پذیر باشه
ممنون میشم کمکم کنین
با تشکر
meisam3322
سه شنبه 22 آذر 1390, 19:32 عصر
با استفاده از توابع API شدنیه. دوست من الان لپ تاپم در دسترسم نیست تا برنامه واست بزارم. حفظ هم نیستم کامل. ولی به اینجا یه نگاهی بنداز (http://www.iranled.com/forum/thread-20688.html). VB6 هست. خیلی راحت میتونی به .NET تغییر بدیشون. فقط به جاری me.hwnd باید me.handle استفاده کنی و باقی تغییرات
Hossis
سه شنبه 22 آذر 1390, 20:12 عصر
این که خیلی ساده و پیش پا افتاده هست
Private IsMouseDown As Boolean = False
Private MouseOffset As Point
Private ClientOffset As Size
Private Sub frmClock_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
IsMouseDown = True
MouseOffset.X = e.X
MouseOffset.Y = e.Y
End If
End Sub
Private Sub frmClock_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If IsMouseDown Then
Me.Location = New Point( _
Me.Location.X + e.X - MouseOffset.X, _
Me.Location.Y + e.Y - MouseOffset.Y)
End If
End Sub
Private Sub frmClock_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
IsMouseDown = False
End Sub
AghaMohsen
سه شنبه 06 دی 1390, 23:13 عصر
اینم من نوشتم
Private IsFormBeingDragged As Boolean = False
Private MouseDownX As Integer
Private MouseDownY As Integer
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = True
MouseDownX = e.X
MouseDownY = e.Y
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = False
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
If IsFormBeingDragged Then
Dim temp As Point = New Point()
temp.X = Me.Location.X + (e.X - MouseDownX)
temp.Y = Me.Location.Y + (e.Y - MouseDownY)
Me.Location = temp
temp = Nothing
End If
End Sub
mgh64120
چهارشنبه 07 دی 1390, 00:29 صبح
سلام دوست عزيز
با استفاده از توابع API
<DllImport("user32.dll")> _
Shared Function ReleaseCapture() As Integer
End Function
Declare Auto Function SendMessageA Lib "user32.dll" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Object) As Integer
Private Const WM_NCLBUTTONDOWN As Integer = 161
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
ReleaseCapture()
SendMessageA(Me.Handle.ToInt32(), WM_NCLBUTTONDOWN, 2, 0)
End Sub
اين هم يك پروژه نمونه.
موفق باشيد...
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.