当前位置: 代码迷 >> VC >> Forms程序如何画图
  详细解决方案

Forms程序如何画图

热度:2597   发布时间:2013-02-25 00:00:00.0
Forms程序怎么画图?
我现在有个小程序要编,以前用MFC的时候,直接用Custom control然后在上面用CDC提供的函数画图,

现在用vs 2005的windows forms的话,请问应该怎么做?在什么上面画图,用什么类画图?谢谢!

------解决方案--------------------------------------------------------
用GDI画图
参考
http://www.cnblogs.com/stg609/archive/2008/03/16/1108333

------解决方案--------------------------------------------------------
绘制线条或空心形状 
获取对将用于绘图的图形对象的引用。有关更多信息,请参见用 GDI+ 创建图形图像。 
' Visual Basic
' Obtains a reference to the graphics object for Button1.
Dim g as Graphics = Button1.CreateGraphics

// C#
Graphics g = Button1.CreateGraphics();

// C++
Graphics* g = button1->CreateGraphics();
创建将用于绘制线条的 Pen 类的实例,并设置所有相应的属性。 
' Visual Basic
Dim myPen as new Pen(Color.Red)
myPen.Width = 5

// C#
Pen myPen = new Pen(Color.Red);
myPen.Width = 5;

// C++
Pen* myPen = new Pen(Color::Red);
myPen->Width = 5;
调用适合要绘制形状的方法,并提供所有需要的参数。下表列出了几个最常用的方法。有关完整列表,请参见图形方法。方法形状
Graphics.DrawLine 方法线条,需要指示起始点和结束点的坐标。
Graphics.DrawPolygon 方法复杂形状,可能需要一个坐标数组。
Graphics.DrawRectangle 方法矩形,需要一个或多个对象(如 Rectangle 对象)作为参数。

' Visual Basic
g.DrawLine(myPen, 1, 1, 45, 65)
g.DrawBezier(myPen, 15, 15, 30, 30, 45, 30, 87, 20)
g.DrawEllipse(myPen, New Rectangle(33, 45, 40, 50))
g.DrawPolygon(myPen, New PointF() {New PointF(1, 1), _
New PointF (20, 10), New PointF(5, 4), New PointF(100, 2), _
New PointF(200, 50), New PointF(39, 45)})

// C#
g.DrawLine(myPen, 1, 1, 45, 65);
g.DrawBezier(myPen, 15, 15, 30, 30, 45, 30, 87, 20);
g.DrawEllipse(myPen, new Rectangle(33, 45, 40, 50));
g.DrawPolygon(myPen, new PointF[] {new PointF(1, 1), 
new PointF (20, 10), new PointF(5, 4), new PointF(100, 2), 
new PointF(200, 50), new PointF(39, 45)});

// C++
g->DrawLine(myPen, 1, 1, 45, 65);
g->DrawBezier(myPen, 15, 15, 30, 30, 45, 30, 87, 20);
g->DrawEllipse(myPen, Rectangle(33, 45, 40, 50));
PointF myPointFArray[] = {PointF(1, 1), 
PointF(20, 10), PointF(5, 4), PointF(100, 2),
PointF(200, 50), PointF(39, 45)};
g->DrawPolygon(myPen, myPointFArray);


------解决方案--------------------------------------------------------
学习中。。。。
  相关解决方案