Public Class Form1 Dim th As Threading.Thread Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing th.Abort() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load th = New Threading.Thread(AddressOf Me.DrawTest) th.Start() End Sub Private Function GetPoint(ByVal Degrees As Integer, ByVal Radius As Integer, ByVal Center As Point) As Point Dim Radians As Single = Degrees * Math.PI / 180.0 Dim pt As New Point pt.X = Center.X + Math.Round(Radius * Math.Cos(Radians)) pt.Y = Center.Y - Math.Round(Radius * Math.Sin(Radians)) Return pt End Function Private Sub DrawTest() Dim tmp1 As Integer = 0 Dim tmp2 As Integer = 360 Do Dim img As New Bitmap(400, 400) Dim lCenter As New Point(200, 200) Dim g As Graphics = Graphics.FromImage(img) g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias g.Clear(Color.Black) g.DrawEllipse(Pens.White, New Rectangle(lCenter.X - 80, lCenter.Y - 80, 160, 160)) Dim sCenter As New Point(Me.GetPoint(tmp1, 111, lCenter)) g.DrawEllipse(Pens.Blue, New Rectangle(sCenter.X - 30, sCenter.Y - 30, 60, 60)) g.DrawEllipse(Pens.Red, New Rectangle(Me.GetPoint(tmp2, 30, sCenter), New Size(1, 1))) Me.CreateGraphics.DrawImage(img, New Point(0, 0)) Threading.Thread.Sleep(50) tmp1 = IIf(tmp1 < 360, tmp1 + 1, 0) tmp2 = IIf(tmp2 > 0, tmp2 - 2, 360) Loop End SubEnd Class
不过绕那个大圆边缘运动就不好搞了。还有timer,求帮助,全部代码
Public Class Form1 Dim th As Threading.Thread Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
th.Abort()
End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
th = New Threading.Thread(AddressOf Me.DrawTest)
th.Start()
End Sub Private Function GetPoint(ByVal Degrees As Integer, ByVal Radius As Integer, ByVal Center As Point) As Point
Dim Radians As Single = Degrees * Math.PI / 180.0 Dim pt As New Point
pt.X = Center.X + Math.Round(Radius * Math.Cos(Radians))
pt.Y = Center.Y - Math.Round(Radius * Math.Sin(Radians)) Return pt
End Function Private Sub DrawTest()
Dim tmp1 As Integer = 0
Dim tmp2 As Integer = 360 Do
Dim img As New Bitmap(400, 400)
Dim lCenter As New Point(200, 200)
Dim g As Graphics = Graphics.FromImage(img)
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.Clear(Color.Black) g.DrawEllipse(Pens.White, New Rectangle(lCenter.X - 80, lCenter.Y - 80, 160, 160)) Dim sCenter As New Point(Me.GetPoint(tmp1, 111, lCenter))
g.DrawEllipse(Pens.Blue, New Rectangle(sCenter.X - 30, sCenter.Y - 30, 60, 60))
g.DrawEllipse(Pens.Red, New Rectangle(Me.GetPoint(tmp2, 30, sCenter), New Size(1, 1))) Me.CreateGraphics.DrawImage(img, New Point(0, 0)) Threading.Thread.Sleep(50)
tmp1 = IIf(tmp1 < 360, tmp1 + 1, 0)
tmp2 = IIf(tmp2 > 0, tmp2 - 2, 360)
Loop End SubEnd Class
{ 最好是这个代码????????
}
using System;
using System.Drawing;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
float angle = 0;
Bitmap memBitmap = new Bitmap(50, 50);
Timer timer = new Timer(); public Form1()
{
InitializeComponent();
using (Graphics g = Graphics.FromImage(memBitmap))
{
g.DrawEllipse(Pens.Red, new Rectangle(0, 0, 49, 49));
g.DrawIcon(SystemIcons.Information, new Rectangle(3, 3, 44, 44));
} timer.Interval = 200;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
angle += 3;
Invalidate();
} protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawEllipse(Pens.Blue, 50, 50, 200, 200);
Point center = new Point(50+100, 50+100);
int distance = 100 + 25; float a = angle / 200.0f * 50.0f;
float x = (float)Math.Cos(a * Math.PI / 180) * distance;
float y = (float)Math.Sin(a * Math.PI / 180) * distance; e.Graphics.TranslateTransform(center.X + x, center.Y + y);
e.Graphics.RotateTransform(angle);
e.Graphics.DrawImageUnscaled(memBitmap, -25, -25);
}
}
}
我要的就是这个。谢谢 gomoku