How to move a control on the window?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
21 views
There is a window in this TextBlock. I need to drag this TextBlock around the window. Been looking on Google, found it is done using PreviewMouseLeftButtonDown, PreviewMouseLeftButtonUp , and MouseMove. But what I couldn't figure out how to do it.
Please tell me.
by | 21 views

1 Answer

0 like 0 dislike
Declare a variable to allow drag and drop
private Boolean can = false;

If the user holds the button, the variable to true.
Pressed to false.
private void lbl_MouseLeftButtonUp(Object sender, MouseButtonEventArgs e) { can = false; } private void lbl_MouseLeftButtonDown(Object sender, MouseButtonEventArgs e) { can = true; }


Drag
private void Window_MouseMove(Object sender, MouseEventArgs e) { // cancel the drag if the user pressed the button. if (!can) return; Control control = this.lbl; //Get the position of the mouse. Double x = e.GetPosition(this).X y = e.GetPosition(this).Y; //Set the value through margin control.Margin = new Thickness(x, y, 0, 0); }
by

Related questions

0 like 0 dislike
1 answer
asked May 20, 2019 by Amffore
0 like 0 dislike
2 answers
110,608 questions
257,187 answers
0 comments
40,796 users