我想避免闪烁,我也不想使用计时器。是否有一种方法可以在表单更新时或图形刷新时使用而不是使用计时器?
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 test
{
public partial class Form1 : Form
{
SolidBrush sb = new SolidBrush(Color.White);
Pen p = new Pen(Color.LightGray, 3);
Graphics g;
int xpos;
int ypos;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
g = panel1.CreateGraphics();
this.DoubleBuffered = true;
}
void Draw(string Shape, int x, int y)
{
panel1.Invalidate();
switch (Shape)
{
case "Circle":
g.FillEllipse(sb, x, y, 20, 20);
g.DrawEllipse(p, x, y, 20, 20);
break;
}
}
private void tmrAnimaion_Tick(object sender, EventArgs e)
{
xpos += 2;
Draw("Circle", xpos, ypos);
if (xpos >= 700)
{
xpos = 0;
ypos += 20;
}
}
}
}
答案 0 :(得分:0)