Один из вариантов что я ваял
Point p1 = new Point();
Point p2 = new Point();
Point p3 = new Point();
bool isDragging = false;
int currentX, currentY;
PictureBox pictureBoxEllips;
PictureBox pictureBoxRect;
PictureBox pictureBoxTrian;
List<Point> lPoint = new List<Point>();
..................................................
void кнопка1()
{
pictureBoxEllips = new PictureBox();
pictureBoxEllips.Size = new Size(60, 60);
pictureBoxEllips.BackColor = Color.White;
Bitmap ell = new Bitmap("ell.bmp");
pictureBoxEllips.Image = (Image)ell;
this.pictureBoxEllips.Cursor = Cursors.Hand;
this.pictureBoxEllips.MouseDown += new MouseEventHandler(this.pictureBoxEllips_MouseDown);
this.pictureBoxEllips.MouseMove += new MouseEventHandler(this.pictureBoxEllips_MouseMove);
this.pictureBoxEllips.MouseUp += new MouseEventHandler(this.pictureBoxEllips_MouseUp);
}
void кнопка2()
{
pictureBoxTrian = new PictureBox();
pictureBoxTrian.Size = new Size(60, 60);
pictureBoxTrian.BackColor = Color.White;
Bitmap trian = new Bitmap("trian.bmp");
pictureBoxTrian.Image = (Image)trian;
this.pictureBoxTrian.Cursor = Cursors.Hand;
this.pictureBoxTrian.MouseDown += new MouseEventHandler(this.pictureBoxTrian_MouseDown);
this.pictureBoxTrian.MouseMove += new MouseEventHandler(this.pictureBoxTrian_MouseMove);
this.pictureBoxTrian.MouseUp += new MouseEventHandler(this.pictureBoxTrian_MouseUp);
}
void кнопка3 ()
{
pictureBoxRect = new PictureBox();
pictureBoxRect.Size = new Size(60, 60);
pictureBoxRect.BackColor = Color.White;
Bitmap rect = new Bitmap("rect.bmp");
pictureBoxRect.Image = (Image)rect;
this.pictureBoxRect.Cursor = Cursors.Hand;
this.pictureBoxRect.MouseDown += new MouseEventHandler(this.pictureBoxRect_MouseDown);
this.pictureBoxRect.MouseMove += new MouseEventHandler(this.pictureBoxRect_MouseMove);
this.pictureBoxRect.MouseUp += new MouseEventHandler(this.pictureBoxRect_MouseUp);
}
void pictureBoxEllips_MouseDown(object sender, MouseEventArgs e)
{
isDragging = true;
currentX = e.X;
currentY = e.Y;
this.Invalidate();
}
void pictureBoxEllips_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
pictureBoxEllips.Top = pictureBoxEllips.Top + (e.Y - currentY);
pictureBoxEllips.Left = pictureBoxEllips.Left + (e.X - currentX);
}
this.Invalidate();
}
void pictureBoxEllips_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
void pictureBoxTrian
аналогично
void pictureBoxRect
аналогично
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (нажата кн.1)
{
pictureBoxEllips.Top = e.Y;
pictureBoxEllips.Left = e.X;
Controls.Add(pictureBoxEllips);
}
if (нажата кн.2)
{
pictureBoxTrian.Top = e.Y;
pictureBoxTrian.Left = e.X;
Controls.Add(pictureBoxTrian);
}
if (нажата кн.3)
{
pictureBoxRect.Top = e.Y;
pictureBoxRect.Left = e.X;
Controls.Add(pictureBoxRect);
}
}
this.Invalidate();
}
int i = 0;
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Point[] point = new Point[4];
if (pictureBoxEllips != null)
{
p1.Y = pictureBoxEllips.Top + pictureBoxEllips.Size.Height / 2;
p1.X = pictureBoxEllips.Left + pictureBoxEllips.Size.Width / 2;
lPoint.Add(p1);
point = lPoint.ToArray();
if (i != 0)
{
g.DrawLine(pen, point[i - 1], point[i]);
}
else
{
g.DrawLine(pen, point[i], point[i]);
}
i++;
}
if (pictureBoxTrian != null)
{
p2.Y = pictureBoxTrian.Top + pictureBoxTrian.Size.Height / 2;
p2.X = pictureBoxTrian.Left + pictureBoxTrian.Size.Width / 2;
lPoint.Add(p2);
point = lPoint.ToArray();
if (i != 0)
{
g.DrawLine(pen, point[i - 1], point[i]);
}
else
{
g.DrawLine(pen, point[i], point[i]);
}
i++;
}
if (pictureBoxRect != null)
{
p3.Y = pictureBoxRect.Top + pictureBoxRect.Size.Height / 2;
p3.X = pictureBoxRect.Left + pictureBoxRect.Size.Width / 2;
lPoint.Add(p3);
point = lPoint.ToArray();
if (i != 0)
{
g.DrawLine(pen, point[i - 1], point[i]);
}
else
{
g.DrawLine(pen, point[i], point[i]);
}
i++;
}
}