Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok I am totally renewing the question and also changed my mind on how I want it to be.

Is there any way that I can create a panel with two different type of labels is it and when I drag a label from the panel it will create a dragable label on the form? So that I can create as many labels as I want to by dragging it on the form. Even just one type of label.

Any ideas will be appreciated.

Thank you,
Posted
Updated 27-May-10 2:23am
v2

there are definitely ways to do it, but all are going to be pretty complicated.

Ideally, you would want the user to draw a Rectangle on the form, select all of the labels within that and then allow them to move it around.

First, you'd have to set up the Rectangle drawing. There are plenty of samples that show how to do that and how to show it on a form.

Then when the user relases the mouse, you would have to use that rectangle to select the elements. You would have to decide whether the whole element has to be within the rectangle, or just part of it.

Also, after the user draws the rectangle, you could draw the icon with the four arrows on it in the top-left corner, or somewhere else or just allow the user to click somewhere within the rectangle. Then, you could change the cursor and start the move process.

It would take some time to program, but its defintiely possible.
 
Share this answer
 
What exactly are you having trouble with? If you want to know how to select all Labels that are direct children of the current Form and then add an event handler to them, that would go something like this:
C#
foreach (Control c in this.Controls)
{
    Label lbl = c as Label;
    if (lbl != null)
    {
        lbl.Click += new EventHandler(delegate(object sender, EventArgs e)
        {
            MessageBox.Show("A label was clicked.");
        });
    }
}
 
Share this answer
 
Yes, you can. You can detect the mouse click/move on the original label and initiate a drag then detect drops. As far as "two different types of labels", I am guessing you only want to be able to drag one kind and then drop the other kind. You could derive a new class from Label (perhaps calling it "SpecialLabel"). Or, you could add information to the Label.Tag property to indicate what type of label it is.
 
Share this answer
 
From your revised description it sounds as though you want to implement a mini forms designer.

If that is correct, then take a look at Crafting a C# Forms Editor from scratch[^] from here on Code Project.

If I am wrong, then please ignore this post. :-D
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900