wpf でウィンドウの周りの行を正常に移動できますが、正しく機能していません。カーソルがドラッグしている線よりも速い場合のようなものです。コードをテストして、何が問題なのかを確認できます。
public partial class MainWindow : Window
{
Line line = new Line();
Point p ;
bool isdragging = false;
public MainWindow()
{
InitializeComponent();
canvas1.Children.Add(line);
Thickness thickness = new Thickness(101, -11, 362, 250);
line.Margin = thickness;
line.Visibility = System.Windows.Visibility.Visible;
line.StrokeThickness = 4;
line.Stroke = System.Windows.Media.Brushes.Black;
line.X1 = 10;
line.X2 = 200;
line.Y1 = 0;
line.Y2 = 70;
line.MouseDown+=new MouseButtonEventHandler(line_MouseDown);
line.MouseMove+=new MouseEventHandler(line_MouseMove);
line.MouseUp+=new MouseButtonEventHandler(line_MouseUp);
}
public void line_MouseDown(object sender, MouseButtonEventArgs e)
{
isdragging = true;
p = e.GetPosition(canvas1);
}
public void line_MouseMove(object sender, MouseEventArgs e)
{
if (isdragging == true && e.LeftButton == MouseButtonState.Pressed)
{
line.X1 += e.GetPosition(canvas1).X - p.X;
line.X2 += e.GetPosition(canvas1).X - p.X;
line.Y1 += e.GetPosition(canvas1).Y - p.Y;
line.Y2 += e.GetPosition(canvas1).Y - p.Y;
}
}
public void line_MouseUp(object sender, MouseButtonEventArgs e)
{
isdragging = false;
}
}
}