UserControl? movingObject; Point offset; Line l = new Line(); bool makingConnection; private void X_PreviewMouseLeftDown(object sender, MouseButtonEventArgs e) { if (Keyboard.IsKeyDown(Key.LeftCtrl)) { movingObject = sender as UserControl; offset = e.GetPosition(canvas); offset.Y -= Canvas.GetTop(movingObject); offset.X -= Canvas.GetLeft(movingObject); canvas.CaptureMouse(); Mouse.OverrideCursor = new Cursor(@"C:\Users\conra\source\repos\WpfApp1\WpfApp1\\grabbing.cur"); } parentControl pc = (parentControl)sender; foreach(connector c in pc.connectors) { if (c.isClicked) { makingConnection = true; l.X1 = e.GetPosition(canvas).X; l.Y1 = e.GetPosition(canvas).Y; } } } private void canvas_PreviewMouseMove(object sender, MouseEventArgs e) { if (movingObject == null) return; Point pp = e.GetPosition(sender as IInputElement); Canvas.SetTop(movingObject, pp.Y - offset.Y); Canvas.SetLeft(movingObject, pp.X - offset.X); if (makingConnection) { l.Stroke = Brushes.Black; l.StrokeThickness = 4; l.X2 = e.GetPosition(sender as IInputElement).X; l.Y2 = e.GetPosition(sender as IInputElement).Y; canvas.Children.Add(l); } }
im trying to get it so that when a button is clicked it make a line from the button position to the position of the mouse on mouse move, this just doesnt add a line and i dont know why