
نوشته شده توسط
مجتبی جوادی
سپاس دوباره دوست گرامی
ولی باز هم آن چیزی که من میخواهم نشد. بعد ار اولین کلیک قبل از اینکه کلیک های بعدی را انجام دهیم، با حرکت دادن کرسر خط بین نقطه کیک شده و موقعیت کرسر همواره نمایش داده شود مثل اتوکد.
با سپاس
public partial class Form1 : Form
{
private List<Point> _points = new List<Point>();
private bool _down;
public Form1()
{
InitializeComponent();
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
_down = true;
_points.Add(e.Location);
pictureBox1.Invalidate();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
if (_points.Count > 1)
{
e.Graphics.DrawLines(Pens.Blue, _points.ToArray());
}
if (_down || (_points.Count == 0))
{
return;
}
using (var pen = new Pen(Color.FromArgb(128, Color.Black), 1f))
{
var endCap = new System.Drawing.Drawing2D.AdjustableArrowCap(5, 5);
pen.CustomEndCap = endCap;
e.Graphics.DrawLine(pen, _points[_points.Count - 1], pictureBox1.PointToClient(Cursor.Position));
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if ((e.Button == MouseButtons.Left) && (_points.Count > 0))
{
_points[_points.Count - 1] = e.Location;
}
pictureBox1.Invalidate();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Cursor = Cursors.Cross;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
_down = false;
pictureBox1.Invalidate();
}
}