Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I make labels draggable from one panel to another with c# and wpf?
    primarykey
    data
    text
    <p>I'm trying to make my text labels draggable, where the text floats above all the other elements as you drag it from one panel to another in a c# wpf application.</p> <p>My labels are made from an array containing the words in a story like so:</p> <pre><code>foreach (string word in lines) { Label myLabel = new Label(); myLabel.Content = word; myLabel.Name = "lbl" + x; myLabel.FontSize = 30; myLabel.Margin = new Thickness(0, -10, 0, -10); myLabel.FontFamily = new FontFamily("Segoe Print"); myLabel.MouseDown += new MouseButtonEventHandler(myLabel_MouseDown); myLabel.MouseMove += new MouseEventHandler(myLabel_MouseMove); myLabel.MouseLeftButtonUp += new MouseButtonEventHandler(myLabel_MouseLeftButtonUp); myLabel.MouseUp += new MouseButtonEventHandler(myLabel_MouseUp); leftPanel.Children.Add(myLabel); myLabelWidth.Add(myLabel.ActualWidth); x++; } </code></pre> <p>In my events I'm trying to figure out what would move the label outside of it's containing panel into another. In wpf I really can't even understand how to set the label position to the mouse position on a hold mouse down and move.</p> <p>I have something which doesn't work at all, but looks like this:</p> <pre><code>void myLabel_MouseMove(object sender, MouseEventArgs s) { Label myLabel = sender as Label if(e.LeftButton == MouseButtonState.Pressed) { myLabel.Left = e.GetPosition(this).X; myLabel.Top= e.GetPosition(this).Y; } } </code></pre> <p>Since this is so far off, I haven't really gotten any further. Any help is appreciated.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload