帮我用c#写一个绘制爱心的程序
时间: 2023-06-27 11:02:09 浏览: 35
好的,以下是用 C# 绘制爱心的程序:
```csharp
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DrawHeart
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
// 设置画笔颜色和粗细
Pen pen = new Pen(Color.Red, 3);
// 绘制左半边的心形
Point[] leftPoints = new Point[7];
leftPoints[0] = new Point(50, 110);
leftPoints[1] = new Point(30, 90);
leftPoints[2] = new Point(20, 70);
leftPoints[3] = new Point(20, 50);
leftPoints[4] = new Point(30, 30);
leftPoints[5] = new Point(50, 10);
leftPoints[6] = new Point(70, 30);
e.Graphics.DrawCurve(pen, leftPoints);
// 绘制右半边的心形
Point[] rightPoints = new Point[7];
rightPoints[0] = new Point(70, 30);
rightPoints[1] = new Point(90, 50);
rightPoints[2] = new Point(100, 70);
rightPoints[3] = new Point(100, 90);
rightPoints[4] = new Point(90, 110);
rightPoints[5] = new Point(70, 130);
rightPoints[6] = new Point(50, 110);
e.Graphics.DrawCurve(pen, rightPoints);
}
}
}
```
在窗口的 `Paint` 事件中,我们使用 `DrawCurve` 方法来绘制左半边和右半边的心形。最后我们需要设置画笔的颜色和粗细,这里我们使用红色和粗细为 3。
运行程序,即可看到绘制出来的爱心图案。
相关推荐













