title: How to connect pictureboxes with connecting line
body: <p>first sorry for my English. I am programming application in windows forms. It is something like Packet Tracer. I have four buttons. When I click on them, they dynamicaly create pictureboxes with picture of Router or Switch,.... Each time I click on the button, new picture box(Switch or Router,...), is created. I can also move with this pictureboxes by mouse. 
  I need to create a button, which connects selected pictureboxes with line(Cable). This pictureboxes should be selected by click on them. It sholud be able to move with this objects(movable line).
  Here is my code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace WindowsFormsApplication1
  {
  
      public partial class Form1 : Form
      {
          int a = 0;
          int b = 0;
          int c = 0;
          int d = 0;
  
          PictureBox[] picturebox = new PictureBox[100];
  
  
  
          public Form1()
          {
  
              InitializeComponent();
  
          }
  
  
          private void router_Click(object sender, EventArgs e)
          {
  
  
              ++a;
  
              picturebox[a] = new PictureBox();
              picturebox[a].Name = "picturebox" + a;
              picturebox[a].Location = new Point(0 + (a-1) *100,100);
              picturebox[a].Size = new Size(70, 70);
              picturebox[a].BorderStyle = BorderStyle.None;
              picturebox[a].SizeMode = PictureBoxSizeMode.StretchImage;
              this.Controls.Add(picturebox[a]);
  
  
              picturebox[a].Image = Image.FromFile(@"D:\\router.jpg");
              picturebox[a].Refresh();
              picturebox[a].MouseDown += new MouseEventHandler(picMouseDown);
              picturebox[a].MouseMove += new MouseEventHandler(picMouseMove);
              picturebox[a].MouseUp += new MouseEventHandler(picMouseUp);
  
  
  
  
          }
  
  
          private void Form1_Load(object sender, EventArgs e)
          {
  
          }
  
          int x = 0;
          int y = 0;
          bool drag = false;
  
          private void picMouseDown(object sender, MouseEventArgs e)
          {
              // Get original position of cursor on mousedown
              x = e.X;
              y = e.Y;
              drag = true;
          }
  
          private void picMouseMove(object sender, MouseEventArgs e)
          {
              if (drag)
              {
                  PictureBox pb = (PictureBox)sender;
                  // Get new position of picture
                  pb.Top += e.Y - y;
                  pb.Left += e.X - x;
                  pb.BringToFront();
              }
          }
  
          private void picMouseUp(object sender, MouseEventArgs e)
          {
              drag = false;
          }
  
          private void switch1_Click(object sender, EventArgs e)
          {
              ++b;
              picturebox[b] = new PictureBox();
              picturebox[b].Name = "picturebox" + b;
              picturebox[b].Location = new Point(0 + (b - 1) * 100, 180);
              picturebox[b].Size = new Size(70, 70);
              picturebox[b].BorderStyle = BorderStyle.None;
              picturebox[b].SizeMode = PictureBoxSizeMode.StretchImage;
              this.Controls.Add(picturebox[b]);
  
  
              picturebox[b].Image = Image.FromFile(@"D:\HP ProBook 450\Desktop\Grafika\switch1.png");
              picturebox[b].Refresh();
              picturebox[b].MouseDown += new MouseEventHandler(picMouseDown);
              picturebox[b].MouseMove += new MouseEventHandler(picMouseMove);
              picturebox[b].MouseUp += new MouseEventHandler(picMouseUp);
  
  
  
          }
  
          private void panel1_Paint(object sender, PaintEventArgs e)
          {
  
          }
  
          private void pc_Click(object sender, EventArgs e)
          {
              ++c;
  
              picturebox[c] = new PictureBox();
              picturebox[c].Name = "picturebox" + c;
              picturebox[c].Location = new Point(0 + (c - 1) * 100, 260);
              picturebox[c].Size = new Size(70, 70);
              picturebox[c].BorderStyle = BorderStyle.None;
              picturebox[c].SizeMode = PictureBoxSizeMode.StretchImage;
              this.Controls.Add(picturebox[c]);
  
  
              picturebox[c].Image = Image.FromFile(@"D:\HP ProBook 450\Desktop\pc.jpg");
              picturebox[c].Refresh();
              picturebox[c].MouseDown += new MouseEventHandler(picMouseDown);
              picturebox[c].MouseMove += new MouseEventHandler(picMouseMove);
              picturebox[c].MouseUp += new MouseEventHandler(picMouseUp);
  
          }
  
          private void server_Click(object sender, EventArgs e)
          {
              ++d;
  
              picturebox[d] = new PictureBox();
              picturebox[d].Name = "picturebox" + d;
              picturebox[d].Location = new Point(0 + (d - 1) * 100, 340);
              picturebox[d].Size = new Size(70, 70);
              picturebox[d].BorderStyle = BorderStyle.None;
              picturebox[d].SizeMode = PictureBoxSizeMode.StretchImage;
              this.Controls.Add(picturebox[d]);
  
  
              picturebox[d].Image = Image.FromFile(@"D:\HP ProBook 450\Desktop\server.png");
              picturebox[d].Refresh();
              picturebox[d].MouseDown += new MouseEventHandler(picMouseDown);
              picturebox[d].MouseMove += new MouseEventHandler(picMouseMove);
              picturebox[d].MouseUp += new MouseEventHandler(picMouseUp);
  
          }
  
  
  
  
      }
  }
  </code></pre>
  
  <p>THank you for your help.</p>