Hi,
Any suggestions how to create a line by clicking two new points then draw a line between them? I am trying to create a distance tool like the one in adobe acrobat.
Hi,
Any suggestions how to create a line by clicking two new points then draw a line between them? I am trying to create a distance tool like the one in adobe acrobat.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
ShankeyPosted Aug 26, 2010, 7:52 AM
Following is your code, Please mark my answer as accepted if it helped you:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Point p1, p2;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (p1.X == 0)
{
p1.X = e.X;
p1.Y = e.Y;
}
else
{
p2.X = e.X;
p2.Y = e.Y;
Graphics graph = this.CreateGraphics();
Pen penCurrent = new Pen(Color.Red, 3);
graph.DrawLine(penCurrent, p1, p2);
}
}
}
}