Create a label from a listbox item

Asked

Viewed 106 times

0

I’m trying to create a prototype application to map a network. The application looks like this: inserir a descrição da imagem aqui

It consists of 2 buttons, one for scan that will fill the list on the right with the desired data and a second button (placeholder) that should create a draggable label (this being the difficulty) with the text equivalent to the item in the list I have selected so that, as soon as it is created, I can drag that same label onto the map in order to map the computer in my application.

I have already gone through several attempts, so far unsuccessful... nor am I sure that I want to create it (draggable label) is possible. For already was already satisfied with the label itself appear.

What I’ve tried so far is:

 private void button2_Click(object sender, EventArgs e)
    {
        Label lbl = new Label
        {
            Text = listBox1.SelectedItem.ToString()
        };
    }

I also tried to integrate the following solution but without success.

So I ask here, is there any way to create a label from a selection of an item in a listbox? And if so, it is possible for this label to be dragged during Runtime?

Thanks in advance.

  • You’re creating the label and you’re not adding anywhere.

  • In Draggable already tested add the Nuget "Control.Draggable". Ai in the code enter the line: ControlExtension.Draggable(button1, true);

  • Another option would be to draw the text instead of creating a label

  • @Focuses I tried your suggestion with the current code but still no result...

  • @LINQ I am sincere, I am not used to working with Forms in c#, I will search how to specify a place pa label.

  • @Vik How would you proceed to "draw text"? Can you develop this idea please?

  • @Mako Enter the code into the constructor, here it worked like this. https://www.youtube.com/watch?v=Rytt-a2cTJA

  • @Mako using the event OnPaint, difficult to explain with just a practical example, maybe this will help: Rendering a control of Windows Forms

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.