我想避免闪烁,我也不想使用计时器。是否有一种方法可以用于更新表单或刷新图形时,我可以使用它来代替计时器?
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;
}
}
}
}