求一直线类,希望从一基类中继承,具有删除,复制,修改,拖动的功能,谢谢
解决方案 »
- c# 开启outlook ,并传入body,但是Body的数据值,是dataset,如何转化成表格的形式显示出来??
- 继续发 我就不信没人会?
- 如何停止Timer,我的Timer停止不了。在线等,急时送分-100
- 非類型化數據集中某表的數據刪除後的問題。
- 执行效率求助
- 求教,怎样用代码将资源文件复制到本地?
- C#网络编程,用TCP协议发送图片!~~~~~~
- 我想从数据库中取出离DateTime.Now时间最近的数据该怎样取?
- 谁能告诉我C# 与VC#.NET的区别在什么地方?(急!!!)
- 急,关于内存释放问题。请C#高手进。
- 怎么调用远得程计算机摄像头
- 在winfrom的panel中网格画一个圆
http://topic.csdn.net/t/20020424/10/671844.html
//声明画笔
Pen myPen = new Pen(Color.Red); //重载OnPaint函数
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
myPen.Width = 5;
g.DrawLine(myPen,1,1,100,100); }
{
public Point LeftTop;
public Point RightBottom;
} public struct DrawPara
{
public Color color;
public DashStyle style;
public int lineWidth;
public DrawPara(Color color1, DashStyle style1, int lineWidth1)
{
color = color1;
style = style1;
lineWidth = lineWidth1;
}
} // 接口类
interface IgraphicsOp
{
void Move(int x, int y, Graphics g);
void MoveTo(int x, int y, Graphics g);
void Draw(Graphics g);
} // 图元基类
public abstract class Elements : ICloneable,IgraphicsOp
{
public DrawPara para; public Elements(DrawPara para1)
{
para = para1;
} public Elements()
{
} public DrawPara Para
{
get
{
return Para;
} set
{
Para = value;
}
} public abstract decimal Area(); public abstract RectArea OverRect(); public abstract void _Move(int x, int y); public abstract void _MoveTo(int x, int y); public abstract void Draw(Graphics g); public void Move(int x, int y, Graphics g)
{
Color oldColor = this.para.color;
//this.para.color = new Pen(this.para.color, this.para.lineWidth);
Draw(g);
_Move(x, y);
this.para.color = oldColor;
Draw(g);
} public void MoveTo(int x, int y, Graphics g)
{
Color oldColor = this.para.color;
//this.para.color = new Pen(this.para.color, this.para.lineWidth);
Draw(g);
_MoveTo(x, y);
this.para.color = oldColor;
Draw(g);
} public virtual object Clone()
{
return MemberwiseClone();
}
} // 直线类
public abstract class Line : Elements
{
private Point start, end; public Line(Point st, Point ed, DrawPara Para)
: base(Para)
{
start.X = st.X;
start.Y = st.Y;
end.X = ed.X;
end.Y = ed.X;
} public Line()
{
} public override decimal Area()
{
return 0.0M;
} public override RectArea OverRect()
{
RectArea Rect = new RectArea();
if (start.X > end.X)
{
Rect.LeftTop.X = end.X;
Rect.RightBottom.X = start.X;
}
else
{
Rect.LeftTop.X = start.X;
Rect.RightBottom.X = end.X;
} if (start.Y > end.Y)
{
Rect.LeftTop.Y = end.Y;
Rect.RightBottom.Y = start.Y;
}
else
{
Rect.LeftTop.Y = start.Y;
Rect.RightBottom.Y = end.Y;
} return Rect;
} public override void Draw(Graphics g)
{
using (Pen myPen = new Pen(para.color, para.lineWidth))
{
myPen.DashStyle = para.style;
g.DrawLine(myPen, start.X, start.Y, end.X, end.Y);
}
} public override void _Move(int x, int y)
{
Size size = new Size(x, y);
this.start += size;
this.end += size;
} public override void _MoveTo(int x, int y)
{
_Move(x-start.X, y-start.Y);
} public override object Clone()
{
Line newLine = new Line();
newLine.para = para;
newLine.start = new Point(start.X, start.Y);
newLine.end = new Point(end.X, end.Y);
return newLine;
} } // 矩形类
public class Rectangle : Elements
{
private Point LeftTop, RightBottom; public Rectangle(Point lt, Point rb, DrawPara Para)
: base(Para)
{
if (lt.X >= rb.X || lt.Y >= rb.Y)
throw new ArgumentNullException();
LeftTop.X = lt.X;
LeftTop.Y = lt.Y;
RightBottom.X = rb.X;
RightBottom.Y = rb.Y;
} public Rectangle()
{
} public override decimal Area()
{
return (RightBottom.X - LeftTop.X) * (RightBottom.Y - LeftTop.Y);
} public static explicit operator RectArea(Rectangle value)
{
RectArea a = new RectArea();
a.LeftTop = value.LeftTop;
a.RightBottom = value.RightBottom;
return a;
} public override RectArea OverRect()
{
return (RectArea)this;
} public override void Draw(Graphics g)
{
using (Pen myPen = new Pen(para.color, para.lineWidth))
{
myPen.DashStyle = para.style;
g.DrawRectangle(myPen, LeftTop.X, LeftTop.Y, RightBottom.X, RightBottom.Y);
}
} public override void _Move(int x, int y)
{
Size size = new Size(x, y);
this.LeftTop += size;
this.RightBottom += size;
} public override void _MoveTo(int x, int y)
{
_Move(x - LeftTop.X, y - LeftTop.Y);
} public override object Clone()
{
Rectangle rectangle = new Rectangle();
rectangle.para = para;
rectangle.LeftTop = new Point(LeftTop.X, LeftTop.Y);
rectangle.RightBottom = new Point(RightBottom.X, RightBottom.Y);
return rectangle;
}
}
{
Line newLine = new Line(); //这报错:错误 1 无法创建抽象类或接口“Stone.Tools.Files.Line”的实例 G:\MyJob\5TMonitor\5TMonitor\5TMonitor\Stone_File.cs 451 28 5TMonitor newLine.para = para;
newLine.start = new Point(start.X, start.Y);
newLine.end = new Point(end.X, end.Y);
return newLine;
}
public abstract class Line : Elements
//改为
public class Line : Elements
//试试
{
Color oldColor = this.para.color;
//this.para.color = new Pen(this.para.color, this.para.lineWidth);//这句怎么得到背景色呢?
Draw(g);
_Move(x, y);
this.para.color = oldColor;
Draw(g);
}
移动时需要用背景色覆盖原来的,怎么得到背景色呢?谢谢
{
Color oldColor = this.para.color;
//this.para.color = new Pen(this.para.color, this.para.lineWidth);//这句怎么得到背景色呢?
Draw(g);
_Move(x, y);
this.para.color = oldColor;
Draw(g);
}
移动时需要用背景色覆盖原来的,怎么得到背景色呢?谢谢
http://www.codeproject.com/KB/graphics/drawtools.aspx