110,571
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CurveDemo
{
public partial class Demo : Form
{
private Color gridColor = Color.DarkGreen;
private int gridWidth = 10;
private int gridHeight = 10;
private Pen gridPen;
Bitmap bmp = null;
Point[] points;
public Demo()
{
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
InitializeComponent();
}
private void Demo_Load(object sender, EventArgs e)
{
gridPen = new Pen(gridColor);
bmp = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(bmp);
for (float i = this.Height; i > 0; i = i - gridHeight)
{
g.DrawLine(gridPen, 0, i, this.Width, i);
}
for (float j = this.Width; j > 0; j = j - gridWidth)
{
g.DrawLine(gridPen, j, 0, j, this.Height);
}
int ii = 2;
Point p1 = new Point(5 + ii, 5 * ii);
Point p2 = new Point(10 * ii, 0);
Point p3 = new Point(15 * ii, 15 * ii);
Point p4 = new Point(20 * ii, 0);
Point p5 = new Point(25 * ii, 25 * ii);
points = new Point[] { p1, p2, p3, p4, p5 };
g.DrawCurve(Pens.Red, points);
gridPen.Dispose();
g.Dispose();
}
private void Demo_Paint(object sender, PaintEventArgs e)
{
Graphics dc = e.Graphics;
dc.FillRectangle(Brushes.Black, this.ClientRectangle);
if (bmp != null)
{
dc.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
}
}
int i = 0;
private void timer1_Tick(object sender, EventArgs e)
{
i++;
Point p1 = new Point(5+i, 5*i);
Point p2 = new Point(10*i, 0);
Point p3 = new Point(15*i, 15*i);
Point p4 = new Point(20*i, 0);
Point p5 = new Point(25*i, 25*i);
points = new Point[] { p1, p2, p3, p4, p5 };
draw();
Refresh();
}
private void draw()
{
Graphics g = Graphics.FromImage(bmp);
g.DrawCurve(Pens.Red,points);
g.Dispose();
}
}
}