formpolygon.cs
来自「csharp课本的源代码」· CS 代码 · 共 55 行
CS
55 行
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PolygonExample
{
public partial class FormPolygon : Form
{
public FormPolygon()
{
InitializeComponent();
}
private void FormPolygon_Paint(object sender, PaintEventArgs e)
{
//创建Graphics对象
Graphics g = e.Graphics;
// 创建一支红色的笔
Pen pen = new Pen(Color.Red);
// 定义多边形的点
Point[] points =
{
new Point (50,50),
new Point (100,50),
new Point (130,90),
new Point (130,140),
new Point (100,180),
new Point (50,180),
new Point (20,140),
new Point (20,90)
};
//绘制多边形轮廓
g.DrawPolygon(pen, points);
//定义第二个多边形的点
Point[] points1 =
{
new Point (250,50),
new Point (300,50),
new Point (330,90),
new Point (330,140),
new Point (300,180),
new Point (250,180),
new Point (220,140),
new Point (220,90)
};
//填充多边形封闭区域
g.FillPolygon(new SolidBrush(Color.Red), points1);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?