How to draw an arrow between two images in WinForms?

To draw an arc with two points, you'll need a predefined angle. I assume you have that part figured out.

To draw an arc with two points, you'll need a predefined angle. I assume you have that part figured out. To do this, you need to draw two arcs, one in each image.

The arc will be bigger than each image, but in the first image you can just clip it where the arc exits the image going toward the second point. In the second image, you need to offset the arc by the x and y distance between the origins of the two images. Then draw the arc in the second image from the first point to the second point and clip that part that is outside the image.

If you need a rubber band arc, you'll have to erase and redraw it whenever the mouse moves. If you want to draw on the space on the form between the images, you can do that using the proper offset.

You have two point, so you can draw a line. Try this: public class Shape { public float X { get; set; } public float Y { get; set; } public Image Image { get; set; } } public class Line { public Shape A { get; set; } public Shape B { get; set; } } and the code: private string _currentTool; private readonly List _shapes; private readonly List _lines; private Line _currentLine; private void Button1Click(object sender, EventArgs e) { _currentTool = "img"; } private void Button2Click(object sender, EventArgs e) { _currentTool = "line"; } private void PictureBox1MouseDown(object sender, MouseEventArgs e) { switch (_currentTool) { case "img": _shapes. Add(new Shape { Image = button1.

Image, X = e. X, Y = e. Y }); pictureBox1.Invalidate(); break; case "line": var selectedShapes = _shapes.

Where(shape => (shape. X - 10 0) { var selectedShape = selectedShapes.First(); _currentLine = new Line {A = selectedShape}; pictureBox1.Invalidate(); } break; } } private void PictureBox1MouseUp(object sender, MouseEventArgs e) { switch (_currentTool) { case "line": var selectedShapes = _shapes. Where(shape => (shape.

X - 10 0) { var selectedShape = selectedShapes.First(); _currentLine. B = selectedShape; _lines. Add(_currentTool); pictureBox1.Invalidate(); } break; } } private void PictureBox1Paint(object sender, PaintEventArgs e) { foreach (var shape in _shapes) { e.Graphics.

DrawImage(shape. Image, shape. X, shape.

Y); } foreach (var line in _lines) { e.Graphics. DrawLine(new Pen(Color. Black), line.A.

X, line.A. Y, line.B. X, line.B.

Y); } }.

I tried this code but it doesn't draw anything :( . Maybe I did something wrong – Lidia Dec 7 '10 at 21:14 @Lidia: Increase 10 and test again, That is worked! – Navid Farhadi Dec 9 '10 at 3:50.

Public class Shape { public float X { get; set; } public float Y { get; set; } public Image Image { get; set; } public bool Test_int(int x, int y) { if (((x = this. X)) && ((y = this. Y))) return true; else return false; } } public class Line { public Shape A { get; set; } public Shape B { get; set; } } and the code private string currentTool; private readonly List shapes; private readonly List lines; private Line currentLine; private void Button1Click(object sender, EventArgs e) { currentTool = "img"; } private void Button2Click(object sender, EventArgs e) { currentTool = "line"; } private void PictureBox1MouseDown(object sender, MouseEventArgs e) { switch (currentTool) { case "img": shapes.

Add(new Shape { Image = button1. Image, X = e. X, Y = e.

Y }); pictureBox1.Invalidate(); break; case "line": foreach (Shape shape1 in shapes) { if (shape1. Test_int(e. X, e.

Y)) { currentLine = new Line { A = shape1 }; } } drawArea1.Invalidate(); break; } } private void PictureBox1MouseUp(object sender, MouseEventArgs e) { switch (currentTool) { case "line": foreach (Shape shape1 in shapes) { if (shape1. Test_int(e. X, e.

Y)) { currentLine. B = shape1; } } lines. Add(currentLine); drawArea1.Invalidate(); break; } } private void PictureBox1Paint(object sender, PaintEventArgs e) { foreach (var shape in shapes) { e.Graphics.

DrawImage(shape. Image, shape. X, shape.

Y); } foreach (var line in lines) { Pen p = new Pen(Color. Gray, 1); Pen p2 = new Pen(Color. Black, 5); e.Graphics.

SmoothingMode = System.Drawing. Drawing2D.SmoothingMode. AntiAlias; p2.

StartCap = System.Drawing. Drawing2D.LineCap. Round; p2.

EndCap = System.Drawing. Drawing2D.LineCap. ArrowAnchor; float x1 = line.A.

X+line.A.Image. Width ; float y1 = line.A. Y+line.A.Image.

Height/2; float x2 = line.B. X; float y2 = line.B. Y+line.B.Image.

Height/2; double angle = Math. Atan2(y2 - y1, x2 - x1); e.Graphics. DrawLine(p, x1, y1, x2, y2); e.Graphics.

DrawLine(p2, x2, y2, x2 + (float)(Math. Cos(angle)), y2 + (float)(Math. Sin(angle))); } }.

This works and I draw the arrow a bit special, I mean I wanted the endCap with the ArrowArc to be bigger then c# draws it. – Lidia Dec 7 '10 at 23:56 Try e.Graphics. ScaleTransform(2, 2); before drawing.

– Navid Farhadi Dec 19 '10 at 14:58.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions