第3个回答 2010-06-05
给你一个我编的例子吧,不过是按按钮移动的
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;
using System.Drawing.Drawing2D;
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Graphics g;
GraphicsPath gp, gpOld;
Matrix RotationTransform, TranslationTransform;
PointF TheRotationPoint;
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(this.pictureBox1.Image);
gp = new GraphicsPath();
gp.AddBezier(110, 110, 110, 115, 120, 115, 125, 130);
gp.AddEllipse(125, 130, 8, 8);
gpOld = gp.Clone() as GraphicsPath;
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
TranslationTransform = new Matrix(1, 0, 0, 1, 0, 0);
TheRotationPoint = new PointF(110.0f, 110.0f);
for (float f = 0.0f; f < 359.0f; f += 45.0f)
{
gp.Transform(TranslationTransform);
RotationTransform.RotateAt(f, TheRotationPoint);
gp.Transform(RotationTransform);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Green, gp);
RotationTransform.Dispose();
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
gp = gpOld.Clone() as GraphicsPath;
}
}
private void button1_Click(object sender, EventArgs e)
{
}
//int iCount = 1;
private void button2_Click(object sender, EventArgs e)
{
//iCount++;
//pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
//g = Graphics.FromImage(this.pictureBox1.Image);
//RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
//TranslationTransform = new Matrix(1, 0, 0, 1, 0, 0);
//TheRotationPoint = new PointF(110.0f, 110.0f);
//for (int i = 0; i < iCount; i++)
//{
// for (float f = 0.0f; f < 359.0f; f += 45.0f)
// {
// gp.Transform(TranslationTransform);
// RotationTransform.RotateAt(f, TheRotationPoint);
// gp.Transform(RotationTransform);
// g.FillPath(Brushes.Orange, gp);
// g.DrawPath(Pens.Green, gp);
// RotationTransform.Dispose();
// RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
// gp = gpOld.Clone() as GraphicsPath;
// }
// TheRotationPoint.X = TheRotationPoint.X + 100;
// TranslationTransform.Translate(100, 0);
//}
}
bool leftDown = false;
bool rightDown = false;
bool upDown = false;
bool downDown = false;
private void button2_MouseDown(object sender, MouseEventArgs e)
{
rightDown = true;
while (rightDown)
{
Application.DoEvents();
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(this.pictureBox1.Image);
TheRotationPoint.X += 2;
TranslationTransform.Translate(2, 0);
for (float f = 0.0f; f < 359.0f; f += 45.0f)
{
//Application.DoEvents();
gp.Transform(TranslationTransform);
RotationTransform.RotateAt(f, TheRotationPoint);
gp.Transform(RotationTransform);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Green, gp);
RotationTransform.Dispose();
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
gp = gpOld.Clone() as GraphicsPath;
}
}
}
private void button2_MouseUp(object sender, MouseEventArgs e)
{
rightDown = false;
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
leftDown = true;
while (leftDown)
{
Application.DoEvents();
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(this.pictureBox1.Image);
TheRotationPoint.X -= 2;
TranslationTransform.Translate(-2, 0);
for (float f = 0.0f; f < 359.0f; f += 45.0f)
{
//Application.DoEvents();
gp.Transform(TranslationTransform);
RotationTransform.RotateAt(f, TheRotationPoint);
gp.Transform(RotationTransform);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Green, gp);
RotationTransform.Dispose();
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
gp = gpOld.Clone() as GraphicsPath;
}
}
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
leftDown = false;
}
private void button3_MouseDown(object sender, MouseEventArgs e)
{
upDown = true;
while (upDown)
{
Application.DoEvents();
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(this.pictureBox1.Image);
TheRotationPoint.Y -= 1;
TranslationTransform.Translate(0, -1);
for (float f = 0.0f; f < 359.0f; f += 45.0f)
{
//Application.DoEvents();
gp.Transform(TranslationTransform);
RotationTransform.RotateAt(f, TheRotationPoint);
gp.Transform(RotationTransform);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Green, gp);
RotationTransform.Dispose();
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
gp = gpOld.Clone() as GraphicsPath;
}
}
}
private void button3_MouseUp(object sender, MouseEventArgs e)
{
upDown = false;
}
private void button4_MouseDown(object sender, MouseEventArgs e)
{
downDown = true;
while (downDown)
{
Application.DoEvents();
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(this.pictureBox1.Image);
TheRotationPoint.Y += 1;
TranslationTransform.Translate(0, 1);
for (float f = 0.0f; f < 359.0f; f += 45.0f)
{
//Application.DoEvents();
gp.Transform(TranslationTransform);
RotationTransform.RotateAt(f, TheRotationPoint);
gp.Transform(RotationTransform);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Green, gp);
RotationTransform.Dispose();
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
gp = gpOld.Clone() as GraphicsPath;
}
}
}
private void button4_MouseUp(object sender, MouseEventArgs e)
{
downDown = false;
}
}
}本回答被提问者采纳