110,537
社区成员
发帖
与我相关
我的任务
分享
public partial class UserLine : UserControl
{
private Point lineStart;
private Point lineEnd;
private int lineWidth;
private Color lineColor;
private Pen pen;
public UserLine()
{
InitializeComponent();
}
public Point LineStart
{
get
{
return lineStart;
}
set
{
this.lineStart=new Point(value.X,value.Y);
}
}
public Point LineEnd
{
get
{
return lineEnd;
}
set
{
this.lineEnd = new Point(value.X, value.Y);
}
}
public int LineWidth
{
get
{
return lineWidth;
}
set
{
this.lineWidth = value;
}
}
public Color LineColor
{
get
{
return lineColor;
}
set
{
this.lineColor = value;
}
}
protected override void OnPaint(PaintEventArgs e)
{
pen=new Pen(LineColor,LineWidth);
base.OnPaint(e);
e.Graphics.DrawLine(pen,LineStart,LineEnd);
}
int i = 0;
private void UserLine_MouseDown(object sender, MouseEventArgs e)
{
if (((e.Y - lineStart.X) / (e.X - lineStart.X)) == ((lineEnd.Y - lineStart.Y) / (lineEnd.X - lineStart.X)))
{
if (e.Button == MouseButtons.Left)
{
i++;
if (i == 2)
{
this.LineColor = Color.Red;
this.LineWidth = 6;
i = 0;
}
else
this.LineColor = Color.Yellow;
}
}
this.Invalidate();
}
}