📄 vc_net的gdi+编程入门教程之图形.htm
字号:
<TBODY>
<TR>
<TD>public: void DrawRectangles(Pen *pen, Rectangle
rects[]);<BR>public: void DrawRectangles(Pen *pen, RectangleF
rects[]);</TD></TR></TBODY></TABLE></P>
<P><BR> 这个方法需要一个Rectangle 或
RectangleF数组。它根据数组的不同的成员值绘制不同的长方形。下面是一个例子代码:<BR><BR></P>
<P>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1>
<TBODY>
<TR>
<TD>private: System::Void Form1_Paint(System::Object * sender,
<BR>System::Windows::Forms::PaintEventArgs * e)<BR>{<BR> Pen
*penCurrent = new Pen(Color::Red);<BR> Rectangle Rect[] = {
Rectangle(20, 20, 120, 20),<BR> Rectangle(20, 50, 120,
30),<BR> Rectangle(20, 90, 120, 40),<BR> Rectangle(20,
140, 120, 60)
};<BR> e->Graphics->DrawRectangles(penCurrent,
Rect);<BR>}</TD></TR></TBODY></TABLE></P>
<P><BR> 上述代码产生如下的效果: <BR><BR></P>
<P>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><IMG
onerror="this.src='http://photocdn.sohu.com/20050420/Img240012859.gif';"
hspace=3
src="VC_NET的GDI+编程入门教程之图形.files/Img240012859.gif"
align=center vspace=1
border=1></TD></TR></TBODY></TABLE><BR>图四、一系列长方形效果图</DIV></TD></TR></TBODY></TABLE></P>
<P><SPAN class=f14><FONT
size=3> <B>二、线条</B><BR><BR> (一)一条直线<BR><BR> 直线连接了两个点,这意味着直线有起点和终点。<BR><BR></P></FONT>
<P>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><IMG
onerror="this.src='http://photocdn.sohu.com/20050420/Img240012861.gif';"
hspace=3
src="VC_NET的GDI+编程入门教程之图形.files/Img240012861.gif"
align=center vspace=1
border=1></TD></TR></TBODY></TABLE><BR>图五、直线示意图</DIV></TD></TR></TBODY></TABLE></P>
<P><BR> 起点和终点是截然不同的两个点,正是基于这一点,直线也可以用两个点(Ponit)来表示,或者用笛卡尔坐标系中的四个坐标数值表示。Graphics提供了以下重载的DrawLine()方法来绘制一条直线,:<BR><BR></P>
<P>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1>
<TBODY>
<TR>
<TD>public: void DrawLine(Pen *pen, Point pt1, Point
pt2);<BR>public: void DrawLine(Pen *pen, PointF pt1, PointF
pt2);<BR>public: void DrawLine(Pen *pen, int x1, int y1, int
x2, int y2);<BR>public: void DrawLine(Pen *pen, float x1,
float y1, float x2, float y2);</TD></TR></TBODY></TABLE></P>
<P><BR> 如果直线用自然数表示,它的起点可以用pt1表示,终点用点pt2表示,如果直线用实数绘制,它在PointF
pt1处开始,在PointF pt2处结束。或者,可以用坐标(x1, y1)来表示起点,用坐标(x2,
y2)表示终点。同样类型的直线可以用十进制数从点(x1, y1) 处到点 (x2,
y2).处。<BR><BR> 下面的代码画了三条直线:<BR><BR></P>
<P>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1>
<TBODY>
<TR>
<TD>private: System::Void Form1_Paint(System::Object * sender,
<BR>System::Windows::Forms::PaintEventArgs * e)<BR>{<BR> Pen
*penCurrent = new
Pen(Color::Red);<BR> e->Graphics->DrawLine(penCurrent,
20, 20, 205, 20);<BR> penCurrent = new
Pen(Color::Green);<BR> e->Graphics->DrawLine(penCurrent,
40, 40, 225, 40);<BR> penCurrent = new
Pen(Color::Blue);<BR> e->Graphics->DrawLine(penCurrent,
30, 60, 215, 60);<BR>}</TD></TR></TBODY></TABLE></P>
<P><BR></P>
<P>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><IMG
onerror="this.src='http://photocdn.sohu.com/20050420/Img240012863.gif';"
hspace=3
src="VC_NET的GDI+编程入门教程之图形.files/Img240012863.gif"
align=center vspace=1
border=1></TD></TR></TBODY></TABLE><BR>图六:绘制三条直线</DIV></TD></TR></TBODY></TABLE></P>
<P><BR> (二)一系列直线<BR><BR> 上述的DrawLine()方法用来画一条直线,如果打算一次画一组直线的话,可以使用Graphics::DrawLines()方法,它重载了两个版本:<BR><BR></P>
<P>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1>
<TBODY>
<TR>
<TD>public: void DrawLines(Pen *pen, Point
points[]);<BR>public: void DrawLines(Pen *pen, PointF
points[]);</TD></TR></TBODY></TABLE></P>
<P><BR> 为了使用这种方法,需要使用代表笛卡尔坐标的自然数定义Point数组,或只用实数定义PointF数组,例子代码如下:<BR><BR></P>
<P>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1>
<TBODY>
<TR>
<TD>private: System::Void Form1_Paint(System::Object * sender,
<BR>System::Windows::Forms::PaintEventArgs * e)<BR>{<BR> Point
Coordinates[] = { Point(20, 10), Point(205, 20),<BR> Point(40,
40), Point(225, 60),<BR> Point(30, 80), Point(215, 100)
};<BR><BR> Pen *penCurrent = new
Pen(Color::Red);<BR> e->Graphics->DrawLines(penCurrent,
Coordinates);<BR>}</TD></TR></TBODY></TABLE></P>
<P><BR> 这将产生如下的效果:<BR><BR></P>
<P>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><IMG
onerror="this.src='http://photocdn.sohu.com/20050420/Img240012865.gif';"
hspace=3
src="VC_NET的GDI+编程入门教程之图形.files/Img240012865.gif"
align=center vspace=1
border=1></TD></TR></TBODY></TABLE><BR>图七、系列直线效果图</DIV></TD></TR></TBODY></TABLE></P>
<P>
<TABLE cellSpacing=0 cellPadding=0 width=590 align=center
border=0><TBODY>
<TR>
<TD><SPAN
class=f14> <B>三、多边形</B><BR><BR> 多边形是如若干个直线互联所围成的图形,换句话说,多边形有多个直线定义,除了第一根直线外,所有直线的起点都是前一根直线的终点,最后一根直线的终点是第一根直线的起点。<BR><BR> 为了画多边形,可以使用Graphics::Polygon()方法,它重载了两个版本:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center
bgColor=#dadacf border=1>
<TBODY>
<TR>
<TD>public: void DrawPolygon(Pen *pen, Point
points[]);<BR>public: void DrawPolygon(Pen *pen, PointF
points[]);</TD></TR></TBODY></TABLE><BR> 使用这个方法时,首先声明一个Point
或 PointF类型的数组,并将它传递给函数的第二个参数。下面是一个例子的代码:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center
bgColor=#dadacf border=1>
<TBODY>
<TR>
<TD>private: System::Void Form1_Paint(System::Object *
sender, <BR>System::Windows::Forms::PaintEventArgs *
e)<BR>{<BR> Point Pt[] = { Point(20, 50), Point(180,
50), Point(180, 20),<BR> Point(230, 70), Point(180,
120), Point(180, 90),<BR> Point(20, 90) };<BR> Pen
*penCurrent = new
Pen(Color::Red);<BR> e->Graphics->DrawPolygon(penCurrent,
Pt);<BR>}</TD></TR></TBODY></TABLE><BR> 这个将产生如下效果:<BR><BR>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><IMG
onerror="this.src='http://photocdn.sohu.com/20050420/Img240012867.gif';"
hspace=3
src="VC_NET的GDI+编程入门教程之图形.files/Img240012867.gif"
align=center vspace=1
border=1></TD></TR></TBODY></TABLE><BR>图八、多边形效果图</DIV></TD></TR></TBODY></TABLE></SPAN></TD></TR></TBODY></TABLE></P></SPAN></SPAN><SPAN
class=f14><FONT size=3> <B><FONT
color=#990000>基于圆的图形</FONT></B><BR><BR> <B>一、椭圆与圆</B><BR><BR> 连续弯曲的线条围成了椭圆。椭圆上的每一个点都相对于中心点来说都存在一个对称点,下图对它进行了说明:<BR><BR></FONT>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><IMG
onerror="this.src='http://photocdn.sohu.com/20050420/Img240012869.gif';"
hspace=3
src="VC_NET的GDI+编程入门教程之图形.files/Img240012869.gif"
align=center vspace=1
border=1></TD></TR></TBODY></TABLE><BR>图九、椭圆示意图</DIV></TD></TR></TBODY></TABLE><BR> 因为一个椭圆可以放入到一个矩形中,所以在GDI+编程中,椭圆用它的外接矩形来定义。为了画一个椭圆,可以使用Graphics::DrawEllipse()方法,这个方法有四个版本:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1>
<TBODY>
<TR>
<TD>public: void DrawEllipse(Pen *pen, Rectangle
rect);<BR>public: void DrawEllipse(Pen *pen, RectangleF
rect);<BR>public: void DrawEllipse(Pen *pen, int x, int y, int
width, int height);<BR>public: void DrawEllipse(Pen *pen,
float x, float y, float width, float
height);</TD></TR></TBODY></TABLE><BR>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><IMG
onerror="this.src='http://photocdn.sohu.com/20050420/Img240012871.gif';"
hspace=3
src="VC_NET的GDI+编程入门教程之图形.files/Img240012871.gif"
align=center vspace=1
border=1></TD></TR></TBODY></TABLE><BR>图十、函数参数示意图</DIV></TD></TR></TBODY></TABLE><BR> 这种方法参数的含义与Graphics::DrawRectangle()方法参数的含义是一样的。<BR><BR> 这里是一个例子:<BR><BR>
<TABLE borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf
border=1>
<TBODY>
<TR>
<TD>private: System::Void Form1_Paint(System::Object *
sender,<BR>System::Windows::Forms::PaintEventArgs *
e)<BR>{<BR> Pen *penCurrent = new
Pen(Color::Red);<BR> e->Graphics->DrawEllipse(penCurrent,
Rectangle(20, 20, 226, 144));<BR>}</TD></TR></TBODY></TABLE><BR>
<TABLE width="90%" align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><IMG
onerror="this.src='http://photocdn.sohu.com/20050420/Img240012873.gif';"
hspace=3
src="VC_NET的GDI+编程入门教程之图形.files/Img240012873.gif"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -