Решил я добить PictureBox'ы
Из одного бокса Drag&Drop'ом тащится картинка. Как сделать это видимым? Ну, чтобы полупрозрачное изображение следовало за курсором.
Буду очень благодарен за исходник, т.к. советы мне уже давали - бестолку
Dim IsMouseDown As Boolean = False
Dim bit As Bitmap
Dim MouseOffset As System.Drawing.Point
' Handles the MouseDown event for both PictureBox controls. This event fires
' when the mouse is in the control's bounds and the mouse button is
' clicked.
Private Sub PictureBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picLeft.MouseDown, picRight.MouseDown, PictureBox1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
IsMouseDown = True
MouseOffset.X = e.X
MouseOffset.Y = e.Y
Dim pic As PictureBox = CType(sender, PictureBox)
bit = CType(pic.Image, Bitmap)
'invoke the drag and drop operation
If Not pic.Image Is Nothing Then
pic.DoDragDrop(pic.Image, DragDropEffects.Move Or DragDropEffects.Copy)
End If
End If
End Sub
' Handles the DragEnter event for both PictureBox controls. DragEnter is the
' event that fires when an object is dragged into the control's bounds.
Private Sub PictureBox_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picLeft.DragEnter, picRight.DragEnter, PictureBox1.DragEnter
' Check to be sure that the drag content is the correct type for this
' control. If not, reject the drop.
If (e.Data.GetDataPresent(DataFormats.Bitmap)) Then
' If the Ctrl key was pressed during the drag operation then perform
' a Copy. If not, perform a Move.
If (e.KeyState And CtrlMask) = CtrlMask Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.Move
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
' Handles the DragDrop event for both PictureBox controls. One handler can be
' used for both PictureBox controls by casting the sender and then checking the
' Name property to determine which control should remove the image.
Private Sub PictureBox_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picLeft.DragDrop, picRight.DragDrop, PictureBox1.DragDrop
Dim pic As PictureBox = CType(sender, PictureBox)
pic.Image = CType(e.Data.GetData(DataFormats.Bitmap), Bitmap)
' Cause the image in the other PictureBox (that is, the PictureBox that was
' not the sender in the DragDrop event) to be removed if the Ctrl key was
' not pressed.
If (e.KeyState And CtrlMask) <> CtrlMask Then
If pic.Name = "picLeft" Then
picRight.Image = Nothing
Else
picLeft.Image = Nothing
End If
End If
End Sub
Dim rectangle As System.Drawing.Rectangle
Private Sub frmMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If IsMouseDown Then
Dim rect As New System.Drawing.Rectangle(Me.Location.X + e.X - MouseOffset.X, Me.Location.Y + e.Y - MouseOffset.Y, bit.Width, bit.Height)
rectangle = rect
Me.Refresh()
End If
End Sub
Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If IsMouseDown Then
bit = CType(picLeft.Image, Bitmap)
e.Graphics.DrawImage(bit, rectangle)
End If
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 110