dodragdrop

L

Lloyd Sheen

Pascal said:
Hello
I'd like to change the appearance (BackColor) of a label only if the
content of it, was passed succesfully to another label, is it possible?
How do I do it?
thank you

Pascal,
You need two things. First in the target you need to set the result of
the operation (in the DragDrop event).

e.Effect = DragDropEffects.Copy

Secondly you need to check the result from the DoDragDrop function to
test what happened.

something like:

if ctl.DoDragDrop(xx,DragDropEffects.Copy) = DragDropEffects.Copy then '
success
 
P

Pascal

Hello and thanks for your answer
but The problem is that the code is in a userctrl, herited from a label: so
i Get an error "exception System.StackOverflowException"
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

Public Sub New()

' This call is required by the Windows Form Designer.

InitializeComponent()

' Add any initialization after the InitializeComponent() call.

'Me.AllowDrop = True

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

Me.DoDragDrop(Me.Text, DragDropEffects.Copy)

Me.BackColor = Color.Red

End Sub

Private Sub Me_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles Me.DragDrop

Me.Text = e.Data.GetData(DataFormats.Text).ToString

If Me.DoDragDrop(Me.Text, DragDropEffects.Copy) = DragDropEffects.Copy Then

Me.BackColor = Color.Green

Else

End If

End Sub


--
http://www.scalpa.info
http://scalpa-production.blogspot.com/






































http://www.scalpa.info
http://scalpa98.blogspot.com/
 
L

Lloyd Sheen

Pascal said:
Hello and thanks for your answer
but The problem is that the code is in a userctrl, herited from a label:
so i Get an error "exception System.StackOverflowException"
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

Public Sub New()

' This call is required by the Windows Form Designer.

InitializeComponent()

' Add any initialization after the InitializeComponent() call.

'Me.AllowDrop = True

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

Me.DoDragDrop(Me.Text, DragDropEffects.Copy)

Me.BackColor = Color.Red

End Sub

Private Sub Me_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles Me.DragDrop

Me.Text = e.Data.GetData(DataFormats.Text).ToString

If Me.DoDragDrop(Me.Text, DragDropEffects.Copy) = DragDropEffects.Copy
Then

Me.BackColor = Color.Green

Else

End If

End Sub


--
http://www.scalpa.info
http://scalpa-production.blogspot.com/






































http://www.scalpa.info
http://scalpa98.blogspot.com/

If you look at your code you are doing a DoDragDrop in the actual DragDrop
event. Check your call stack and you will see the problem.

PS please dont top-post it makes following this thread difficult.

LS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top