Public Class Form1 Dim pic As New List(Of PictureBox) Dim mousex, mousey As Integer Dim drag As Boolean = False Private Sub pic_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = Windows.Forms.MouseButtons.Left Then Me.Cursor = Cursors.Hand drag = True mousex = -e.X mousey = -e.Y Dim left As Integer = Me.PointToClient(MousePosition).X - sender.location.x Dim right As Integer = Me.PointToClient(MousePosition).Y - sender.location.y Dim width As Integer = Me.ClientSize.Width - (sender.width - left) Dim height As Integer = Me.ClientSize.Height - (sender.width - right) Windows.Forms.Cursor.Clip = Me.RectangleToScreen(New Rectangle(left, right, width, height)) sender.invalidate() End If End Sub Private Sub pic_Mousemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If drag Then Dim mposition As New Point() mposition = Me.PointToClient(MousePosition) mposition.Offset(mousex, mousey) sender.location = mposition End If End Sub Private Sub pic_Mouseup(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) drag = False Windows.Forms.Cursor.Clip = Nothing Me.Cursor = Cursors.Arrow sender.invalidate() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If pic(1).Bounds.IntersectsWith(pic(2).Bounds) Then Button1.Enabled = False Else pic(1).Enabled = True End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As New PictureBox a.Image = Image.FromFile("C:\Users\Rose\Desktop\pic.jpeg") Dim pic = a Me.Controls.Add(pic) AddHandler pic.MouseDown, AddressOf pic_MouseDown AddHandler pic.MouseMove, AddressOf pic_Mousemove AddHandler pic.MouseUp, AddressOf pic_Mouseup End Sub End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)