bool inDrag; Point dragPoint; private void Body3D_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { dragPoint = e.GetPosition(this); inDrag = true; } private void Body3D_MouseMove(object sender, MouseEventArgs e) { if (inDrag) { Point pointMoveTo; // Find the current mouse position in screen coordinates. pointMoveTo = this.PointToScreen(e.GetPosition(this)); // Compensate for the position the control was clicked. pointMoveTo.Offset(-dragPoint.X, -dragPoint.Y); // Compensate for the non-client region (title bar). // This code is not necessary if you explicitly hide the title bar // by setting the form's BorderStyle to None. //pointMoveTo.Offset(0, -25); // Move the window. this.Top = pointMoveTo.X; this.Left = pointMoveTo.Y; } } private void Body3D_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { inDrag = false; }
public partial class MyWindow : Window { //... protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); this.DragMove(); //begin dragging mode } //... } //class MyWindow
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)