P
Pascal
Ok
thanks
pascal
thanks
pascal
Ok
thanks
pascal
Pascal said:I tried your code without success... Nothing visualy happens when i drag
the label upon the button or the button upon the label..
Finally i catch the behavior i wanted like this :
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
<Category("Common control"), Browsable(True), Description("Ca c'est du
label de chez scalpa")> _
<ToolboxBitmap(GetType(Lbl_ClassLibrary.MonLabel), "MonLabel.bmp")> _
Public Class MonLabel
Inherits Windows.Forms.Label
#Region " Private declarations "
Private MouseIsDown As Boolean = False
Private b_SuccessDrop As Boolean = False
Private b_LblSource As Boolean = False
Private retCode As DragDropEffects
#End Region
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.BorderStyle = Windows.Forms.BorderStyle.FixedSingle
Me.MinimumSize = New Size(80, 25)
Me.Dock = DockStyle.Fill
Me.TextAlign = ContentAlignment.MiddleCenter
Me.BackColor = SystemColors.Control
End Sub
#Region "Events"
'copier le contenu du label quand clic gauche
Private Sub Me_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
' Set a flag to show that the mouse is down.
MouseIsDown = True
' If the drag operation was a move then set the label.text to "".
If (Me.DoDragDrop(Me.Text, DragDropEffects.Move) =
DragDropEffects.Move) Then
Me.Text = ""
Else
End If
End Sub
Private Sub Me_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If MouseIsDown And e.Button = MouseButtons.Left And Me.Text <> ""
Then
' Initiate dragging because all conditions are ok
Me.DoDragDrop(Me.Text, DragDropEffects.Move)
Else
Exit Sub
End If
MouseIsDown = False
End Sub
Private Sub Me_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
' Check the format of the data being dropped.
If (e.Data.GetDataPresent(DataFormats.Text)) Then
If Me.Text = "" Then
' Display the Move cursor.
e.Effect = DragDropEffects.Move
Else
' Display the no-drop cursor.
e.Effect = DragDropEffects.None
End If
Else
' Display the no-drop cursor.
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub Me_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
'Is there some data to move?
If e.Data.GetDataPresent(DataFormats.Text) Then
If e.Effect = DragDropEffects.Move Then
Me.Text = e.Data.GetData(DataFormats.Text).ToString
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
#End Region
#Region "Properties"
'''-----------------------------------------------------------------------------
''' <summary>
''' Sets or returns source or target?
''' </summary>
''' <history>
''' [scalpa]
''' </history>
'''-----------------------------------------------------------------------------
<Category("Monlabel"), _
Description("Label source or target?"), _
DefaultValue(GetType(Boolean), "False")> _
Public Property bLblSource() As Boolean
Get
Return b_LblSource
End Get
Set(ByVal value As Boolean)
b_LblSource = value
End Set
End Property
#End Region
End Class