public myWindow() { this.InitializeComponent(); Body3D.MouseLeftButtonDown += new MouseButtonEventHandler(Body3D_MouseLeftButtonDown); Body3D.MouseLeftButtonUp += new MouseButtonEventHandler(Body3D_MouseLeftButtonUp); Body3D.MouseMove += new MouseEventHandler(Body3D_MouseMove); } 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.Left = pointMoveTo.X; this.Top = pointMoveTo.Y; } } private void Body3D_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { inDrag = false; }}
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)