如何用gdi+画一条直线
如何用gdi+画一条直线
[解决办法]
Graphics g=this.createGraphics();
g.(new Pen(Brushes.DeepSkyBlue)
, PointX, PointY)
[解决办法]
this.createGraphics();
控件都有creategrsphics的方法.你要在哪里画就在哪个对象上创建,form iamge都可以
[解决办法]
Graphics g=this.createGraphics();
Point pt1,pt2;
g.DrawLine(Pens.Red,pt1,pt2);
写三个事件,MouseDown,MouseMove,MouseUp
protected void MouseDown(MouseEventArgs e)
{
pt1.X=pt2.X = e.X;
pt1.Y=pt2.Y = e.Y;
}
protected void MouseMove(MouseEventArgs e)
{
pt2.X = e.X;
pt2.Y = e.Y;
DrawLine(Pens.Red);
}
protected void MouseUp(MouseEventArgs e)
{
pt2.X = e.X;
pt2.Y = e.Y;
DrawLine(Pens.Green);
}
private void DrawLine(Pen pen)
{
Graphics g=this.createGraphics();
g.DrawLine(pen,pt1,pt2);
}