title: WPF C# Canvas Drawing Line connecting buttons
body: <p>i am testing out how to draw a line that connects the button to another button upon clicking the the button, i got confuse with the coordinates and the <code>settop</code> <code>setleft</code>, how do they actually work in simple terms. i know that we have to set the <code>X2</code> <code>Y2</code> ( subtract of start point with end point ) of the line, but i really confuse at what to subtract and how do i do this .</p>
  
  <p>this is so far what i have tried: </p>
  
  <pre><code> int k = 20;
   for (int i = 0; i &lt; 4; i++)
   {
        Button btn = new Button();
        btn.Content = i.ToString();
        btn.Height = 20;
        btn.Width = 20;
        Canvas.SetTop(btn,k); // 20
        Canvas.SetLeft(btn, 20); // 10 
        Canvas1.Children.Add(btn);
        btn.PreviewMouseDown += (source, e) =&gt;
        {
            // No idea how to set X2 , Y2 for the line's end point.
            Line line = new Line();
            //line.X2 = ;
            //line.Y2 = ;
            line.Stroke = Brushes.Red;
            line.StrokeThickness = 4;
            Canvas.SetLeft(line,40); // Suppose this is where the line should start 
            Canvas.SetTop(line ,40); // for button " 0 " .
            Canvas1.Children.Add(line);
        };
        k += 20;
   }
   for (int i = 0; i &lt; 4; i++)
   {
        Button btn2 = new Button();
        btn2.Content = i.ToString();
        btn2.Height = 20;
        btn2.Width = 20;
        Canvas.SetTop(btn2, k); // 20
        Canvas.SetRight(btn2, 20); // 10
        Canvas1.Children.Add(btn2);
        btn2.PreviewMouseDown += (source, e) =&gt;
        {
            //Draw Line to connect here.
        };
        k += 20;
    }
  </code></pre>
  
  <p>i am trying to draw a line from btn to btn2 . </p>
  
  <p><img src="https://i.stack.imgur.com/rmqfj.jpg" alt="Preview image"></p>
  
  <p>And also , how do i adjust the buttons to be in the same level, for now the right buttons ( btn2 ) is abit lower than the left buttons ( btn) and i want to draw a line to connect the right buttons to the left buttons upon clicking button 0 , so 0 will draw a line to 0 .</p>