6 Replies - 6857 Views - Last Post: 25 July 2013 - 04:47 AM Rate Topic: -----

#1 Agent_Orange30   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-July 13

Create Dynamic Label with Drag and Drop Function

Posted 24 July 2013 - 06:00 PM

Hello All,



I want to make a Label that I can drag and drop. At the same time when I drag the original label it will leave a copy of it self.



Example: When I drag Label1 it will leave another Label to its Original Position( Lets Name the New Label1 in Original Position as Label2),

Then I should also be able to drag Label2 and Leave another Label (Label3), I also want to drag Label1 and Label2 but it should not leave a copy.



Here is my code: I been able to do multiplication of Label and Dragging of Label but I cannot drag all Labels:

    Public Class Form1  
        Dim cursorX, cursorY As Integer  
        Dim dragging As Boolean  
        Dim labelno As Integer = 1  
      
        Private Sub Control_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown  
            dragging = True  
            cursorX = e.X  
            cursorY = e.Y  
      
      
            Dim label2 As New Label  
            labelno += 1  
            label2.Location = New Point(Label1.Location.X, Label1.Location.Y)  
            label2.Name = "Label" + labelno.ToString  
            label2.Text = label2.Location.ToString  
            Me.Controls.Add(label2)  
      
        End Sub  
      
        Private Sub Control_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp  
            dragging = False  
        End Sub  
      
        Private Sub control_MouseMOve(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove  
            If dragging Then  
                Dim ctrl As Control = CType(sender, Control)  
                ctrl.Left = (ctrl.Left + e.X) - cursorX  
                ctrl.Top = (ctrl.Top + e.Y) - cursorY  
                ctrl.BringToFront()  
            End If  
        End Sub  




If you have clarification please inform me.



Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Create Dynamic Label with Drag and Drop Function

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15356
  • View blog
  • Posts: 61,553
  • Joined: 12-June 08

Re: Create Dynamic Label with Drag and Drop Function

Posted 24 July 2013 - 06:03 PM

... so what's the question? Is there an error? If so what is the error text and location? Is it not functioning as expect? If so what is it doing and what should it be doing? Remember we are not there with you and cannot infer what the problem is without you telling us more detail!
Was This Post Helpful? 0
  • +
  • -

#3 Agent_Orange30   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-July 13

Re: Create Dynamic Label with Drag and Drop Function

Posted 24 July 2013 - 06:08 PM

View Postmodi123_1, on 24 July 2013 - 06:03 PM, said:

... so what's the question? Is there an error? If so what is the error text and location? Is it not functioning as expect? If so what is it doing and what should it be doing? Remember we are not there with you and cannot infer what the problem is without you telling us more detail!



Well what I want is to achieve this:

"I want to make a Label that I can drag and drop. At the same time when I drag the original label it will leave a copy of it self."

Can you give me an Idea or reference on how to do it?

I want to drag the drop all the labels that I dynamically created. If also possible when I right click on a certain Label it should be deleted.

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry   User is offline

  • Coding Geezer
  • member icon

Reputation: 314
  • View blog
  • Posts: 1,296
  • Joined: 12-September 12

Re: Create Dynamic Label with Drag and Drop Function

Posted 24 July 2013 - 07:19 PM

View PostAgent_Orange30, on 24 July 2013 - 07:08 PM, said:

Well what I want is to achieve this:

"I want to make a Label that I can drag and drop. At the same time when I drag the original label it will leave a copy of it self."

Perhaps you have misunderstood modi123_1's post. He was not asking you what you wantd to accomplish, but rather, what happens when you try to accomplish it. Do you get an error? Does the drag not work? Does the drop not work? Does the duplicate not appear?
Was This Post Helpful? 0
  • +
  • -

#5 Agent_Orange30   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-July 13

Re: Create Dynamic Label with Drag and Drop Function

Posted 24 July 2013 - 07:47 PM

View Postlar3ry, on 24 July 2013 - 07:19 PM, said:

View PostAgent_Orange30, on 24 July 2013 - 07:08 PM, said:

Well what I want is to achieve this:

"I want to make a Label that I can drag and drop. At the same time when I drag the original label it will leave a copy of it self."

Perhaps you have misunderstood modi123_1's post. He was not asking you what you wantd to accomplish, but rather, what happens when you try to accomplish it. Do you get an error? Does the drag not work? Does the drop not work? Does the duplicate not appear?



Ah OK Sorry,

Actually "I been able to do multiplication of Label and Dragging of Label but I cannot drag all Labels"

I have been able to drag and duplicate the source Label.

Now what I want is to able to drag the duplicated labels but this time they should not leave a copy.
Was This Post Helpful? 0
  • +
  • -

#6 lar3ry   User is offline

  • Coding Geezer
  • member icon

Reputation: 314
  • View blog
  • Posts: 1,296
  • Joined: 12-September 12

Re: Create Dynamic Label with Drag and Drop Function

Posted 24 July 2013 - 09:50 PM

View PostAgent_Orange30, on 24 July 2013 - 08:47 PM, said:

Actually "I been able to do multiplication of Label and Dragging of Label but I cannot drag all Labels"

I have been able to drag and duplicate the source Label.

Now what I want is to able to drag the duplicated labels but this time they should not leave a copy.

Well, I still don't really get what you are trying to do, but here's what I see in your code:

You are only accepting MouseDown events for Label1, and there are no events for the dynamically created labels, so as long as you keep moving Label1, it will keep depositing a new, dynamically created label where it was moved from. The rest of the labels will not react to a MouseDown event.

I would suggest using either a List(of Label), or an Array of labels, and create ALL your labels dynamically, including Label1, and adding them all to the List or placing them sequentially in the array. When you create a new label, name it as you do now, and use use AddHandler() to point to the event handler, which could be the event handler you have now, but with the Handles clause removed from the end of it.

Then, when you have a MouseDown event, you can check for the name of the Label and decide whether or not to plunk down another label in its place. As well, when you have a MouseDown event, check to see if it's a Right-Click, and delete the Label if you want. If you want to delete labels, a List(Of T) is the best way, because you don't have to contend with empty entriesin an array.

Let me know if I've understood you correctly.
Was This Post Helpful? 0
  • +
  • -

#7 deery5000   User is offline

  • D.I.C Lover

Reputation: 87
  • View blog
  • Posts: 1,097
  • Joined: 09-May 09

Re: Create Dynamic Label with Drag and Drop Function

Posted 25 July 2013 - 04:47 AM

I don't even think you creating a duplicate

you have a label -> label1

when you "Mouse_Down" on this control you create a new label (label2), label 1 still remains


So you have a new control label2 that sits onto of label1, you want to drag this but you cant because every time you mouse_down you get a new control. (this is what the code is telling it to do)

My suggestions,

1. set the location of new label to be at a different position as label1.
2. before you add the control to the panel add a handler (addHandler -> google this)
3. You can now control what happens to the control on the mouse down (add the drag and drop material)

Hope this helps
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1