Graphics.DrawRectangle 方法

命名空间:System.Drawing

程序集:System.Drawing.dll, System.Drawing.Common.dll

1、DrawRectangle(Pen, Rectangle)

功能:绘制由 Rectangle 结构指定的矩形。

参数

第一个参数Pen,它确定线条的颜色、宽度和样式。

第二个参数Rectangle表示要绘制的矩形的 Rectangle 结构。

示例

//创建Graphics对象,GPS局部变量

Graphics GPS = this.CreateGraphics();

Pen blackPen = new Pen(Color.Black, 3);

// Create rectangle.

Rectangle rect = new Rectangle(100, 100, 200, 200);

// Draw rectangle to screen.

GPS.DrawRectangle(blackPen, rect);

2、DrawRectangle(Pen, Int32, Int32, Int32, Int32)

功能:绘制由坐标对、宽度和高度指定的矩形。

参数

 第一个参数Pen,它确定线条的颜色、宽度和样式。

第二个参数Int32,要绘制的矩形的左上角的 x 坐标。

 第三个参数Int32,要绘制的矩形的左上角的 y 坐标。

第四个参数Int32,要绘制的矩形的宽度。

 第五个参数Int32,要绘制的矩形的高度。

说明:DrawRectangle(Pen, Single, Single, Single, Single)功能及用法同上,只是数据类型不同,Int32Single

示例

//创建Graphics对象,GPS局部变量

Graphics GPS = this.CreateGraphics();

Pen blackPen = new Pen(Color.Black, 3);

// Create location and size of rectangle.

int x = 100;

int y = 100;

int width = 200;

int height = 200;

// Draw rectangle to screen.

GPS.DrawRectangle(blackPen, x, y, width, height);

 

发布了154 篇原创文章 · 获赞 69 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/haier123888/article/details/104163723