在C#里面画直线的
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
namespace Line
{
public class LineControl : Control
{
private LineType m_lineType = LineType.Horizontal;
private Color m_lineColor = Color.Blue;
private Color m_shadowColor = Color.Gray;
private int m_lineWidth = 2;
private Size m_shadowOffset = new Size(1, 1);
public LineControl()
{
this.SetStyle(ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
this.SetStyle(ControlStyles.UserMouse |
ControlStyles.Selectable |
ControlStyles.StandardClick |
ControlStyles.StandardDoubleClick, false);
}
[Category("线")]
[Description("阴影的偏移量")]
[DefaultValue(typeof(Size), "1,1")]
public Size ShadowOffset
{
get { return m_shadowOffset; }
set
{
m_shadowOffset = value;
this.SetSize();
this.Invalidate();
}
}
[Category("线")]
[Description("宽度")]
[DefaultValue(2)]
public int LineWidth
{
get { return m_lineWidth; }
set
{
if (value < 1) value = 1;
m_lineWidth = value;
this.SetSize();
this.Invalidate();
}
}
[Category("线")]
[Description("类型")]
[DefaultValue(typeof(LineType), "Horizontal")]
public LineType LineType
{
get { return m_lineType; }
set
{
if (m_lineType != value)
{
int linelen = 0;
if (m_lineType == LineType.Horizontal)
{
linelen = this.Width;
}
else
{
linelen = this.Height;
}
m_lineType = value;
if (value == LineType.Horizontal)
{
this.Width = linelen;
}
else
{
this.Height = linelen;
}
this.SetSize();
this.Invalidate();
}
&n
补充:软件开发 , C# ,