That’s the code i have to drag my window. It kinda works! Kind of…
Private Point startPoint;
private void Window_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
startPoint = e.GetPosition(null);
}
private void Window_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point relative = e.GetPosition(null);
Point AbsolutePos = new Point(relative.X + this.Left, relative.Y + this.Top);
this.Top = AbsolutePos.Y - startPoint.Y;
this.Left = AbsolutePos.X - startPoint.X;
}
}
The problem is if i move the mouse too fast, it will go out of the window and stop raising the movemouse event. Second, the dragging window is not smooth at all which makes me believed i’m not doing it the right way. Third, I’ve tried this on Window_MouseLeftButtonDown which would fire the event just once per mouse click.
I’m a beginner, a simple example free of Dropping and Data transferring would be appreciated by me and many others beginners like me. thanks in advance to Stack OverFlow users willing to help.
Losing the mouse is a result of failing to capture the mouse. The standard procedure is:
As far as the performance, you are going about it the right way. The speed is limited by the repainting of the window itself and any windows the window passes over and how fast your computer is and what else is going on on computer while you are dragging it.