Public Class Form1 Private pic As New ArrayList() Dim drag As Boolean = False Dim mousex, mousey As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.Click Dim a As New PictureBox a.Location = New System.Drawing.Point(50, 50) a.BackColor = Color.Khaki Me.Controls.Add(a) pic.Add(a) AddHandler a.MouseDown, AddressOf pic_MouseDown AddHandler a.MouseMove, AddressOf pic_Mousemove AddHandler a.MouseUp, AddressOf pic_Mouseup AddHandler a.MouseClick, AddressOf gg If qq(a) = True Then Debug.Print("collision occured.") Else Debug.Print("no intersectin") End If End Sub Public Sub gg(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = Windows.Forms.MouseButtons.Right Then Dim msg As MsgBoxResult = MsgBox("Do you want to remove?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "warning") If msg = MsgBoxResult.Yes Then Me.Controls.Remove(sender) End If End If End Sub Public Function qq(ByVal pb As PictureBox) As Boolean For Each q As PictureBox In pic If Not q Is pb Then If q.Bounds.IntersectsWith(pb.Bounds) Then Return True Else Continue For End If End If Next Return False End Function 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 End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)