14-01-22, 11:59 PM
(14-01-22, 11:48 PM)ابراهيم ايبو كتب :السلام عليكم ورحمة الله وبركاتهاخي الكريم لو تلاحظ توقيعي(البرمجة ليست مجرد كود بل هي منهج تفكير منطقي لحل المشكلات)الان انت وضعت صورة في خلفية الفورم قم باضافة Panel اعلى وسط الصورة بشكل مستطيل يشبه شريط عنوان الفورم
واجعل لون الخلفية له Transparent حتى لايظهر (هو موجود فوق الصورة )
الان اكتب له هذا الكود
كود :
Dim a As Integer
Dim b As Integer
Private Sub planel1_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel1.MouseDown
a = Panel.MousePosition.X - Me.Location.X
b = Panel.MousePosition.Y - Me.Location.Y
End Sub
Private Sub panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
Dim newPoint As New System.Drawing.Point()
If e.Button = MouseButtons.Left Then
newPoint = Panel.MousePosition
newPoint.X = newPoint.X - (a)
newPoint.Y = newPoint.Y - (b)
Me.Location = newPoint
End If
End Sub
وهذه طريقة اخرى فقط غير المسميات (اسم البانل).... يتضمنها حدث رفع الماوس من على البنل
كود :
Private MouseOffset As Point
Private IsLeftButtonDown As Boolean = False
Private Sub PlayerPanel_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PlayerPanel.MouseDown
If e.Button = MouseButtons.Left Then
IsLeftButtonDown = False
End If
Dim xOffset As Integer
Dim yOffset As Integer
If e.Button = MouseButtons.Left Then
xOffset = -e.X - SystemInformation.FrameBorderSize.Width
yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height
MouseOffset = New Point(xOffset, yOffset)
IsLeftButtonDown = True
End If
End Sub
Private Sub PlayerPanel_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PlayerPanel.MouseMove
If IsLeftButtonDown Then
Dim MousePosition As Point = Control.MousePosition
MousePosition.Offset(MouseOffset.X, MouseOffset.Y)
Location = MousePosition - PlayerPanel.Location
End If
End Sub
Private Sub PlayerPanel_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PlayerPanel.MouseUp
If e.Button = MouseButtons.Left Then
IsLeftButtonDown = False
End If
End Sub
