formcurve.cs
来自「csharp课本的源代码」· CS 代码 · 共 88 行
CS
88 行
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace DrawCurveExample
{
public partial class FormCurve : Form
{
public FormCurve()
{
InitializeComponent();
}
private void FormCurve_Paint(object sender, PaintEventArgs e)
{
//创建Graphics对象
Graphics g = e.Graphics;
// 创建一支红色的笔
Pen redPen = new Pen(Color.Red, 3);
// 定义组成曲线的点
Point[] curve1points =
{
new Point (150,100),new Point (200,50),
new Point (250,100),new Point (300,50)
};
g.DrawCurve(redPen, curve1points);
// 创建一支黑色的笔
Pen blackPen = new Pen(Color.Black, 3);
//定义曲线强度
// 定义组成曲线的点
Point[] curve2points =
{
new Point (350,100),
new Point (400,50),
new Point (450,100),
new Point (500,50)
};
float tension = 1.0f;
g.DrawCurve(blackPen, curve2points, tension);
// 定义组成曲线的点
Point[] curve3points =
{
new Point (150,200),
new Point (200,150),
new Point (250,200),
new Point (300,150)
};
g.DrawClosedCurve(redPen, curve3points);
// 定义组成曲线的点
Point[] curve4points =
{
new Point (350,200),
new Point (400,150),
new Point (450,200),
new Point (500,150)
};
float tension1 = 1.0f;
FillMode afillmode = FillMode.Alternate;
g.DrawClosedCurve(redPen, curve4points, tension1, afillmode);
// 定义组成贝塞尔曲线的点
Point istart = new Point(150, 300);
Point icontrol1 = new Point(200, 180);
Point icontrol2 = new Point(250, 250);
Point iend = new Point(300, 300);
// 绘制贝塞尔曲线
g.DrawBezier(blackPen, istart, icontrol1, icontrol2, iend);
// 定义组成贝塞尔曲线的点
Point jstart = new Point(350, 300);
Point jcontrol1 = new Point(400, 200);
Point jcontrol2 = new Point(420, 250);
Point jend1 = new Point(440, 300);
Point jcontrol3 = new Point(460, 360);
Point jcontrol4 = new Point(480, 400);
Point jend2 = new Point(500, 300);
Point[] bezierpoints =
{
jstart,jcontrol1,jcontrol2,jend1,jcontrol3,jcontrol4,jend2
};
// 绘制贝塞尔曲线
g.DrawBeziers(redPen, bezierpoints);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?