我怎么能借鉴面板,因此不眨眼? [英] How can I draw on Panel so it does not blink?
本文介绍了我怎么能借鉴面板,因此不眨眼?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码。当我移动光标移到表格它的工作原理,圆移动,但它闪烁。我怎样才能解决这个问题。
公共部分类Preprocesor:表
{
INT的x,y;
图形克;
公共Preprocesor()
{
的InitializeComponent();
}
私人无效Preprocesor_Load(对象发件人,EventArgs五)
{
G = pnlMesh.CreateGraphics();
}
私人无效pnlMesh_Paint(对象发件人,PaintEventArgs的E)
{
g.Clear(Color.White);
g.FillEllipse(Brushes.Black,X,Y,10,10);
}
私人无效pnlMesh_MouseMove(对象发件人,MouseEventArgs E)
{
X = e.X;
Y = e.Y;
pnlMesh.Invalidate();
}
}
解决方案
您需要利用双缓冲的控制。
请一类,它继承了控制
和集合的DoubleBuffered = TRUE;
在控制你的面板,而不是它不会有任何闪烁的构造(这是一个受保护的属性)。结果
使用。
此外,你不应该存储图形
对象后,结果
相反,你应该吸取 e.Graphics
在油漆
处理程序。
This is my code. When I move cursor over Form it works, circle is moving but it is blinking. How can I fix this?
public partial class Preprocesor : Form
{
int x, y;
Graphics g;
public Preprocesor()
{
InitializeComponent();
}
private void Preprocesor_Load(object sender, EventArgs e)
{
g = pnlMesh.CreateGraphics();
}
private void pnlMesh_Paint(object sender, PaintEventArgs e)
{
g.Clear(Color.White);
g.FillEllipse(Brushes.Black, x, y, 10, 10);
}
private void pnlMesh_MouseMove(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
pnlMesh.Invalidate();
}
}
解决方案
You need to draw on a double-buffered control.
Make a class that inherits Control
and sets DoubleBuffered = true;
in the constructor (this is a protected property).
Use that control instead of your panel it there won't be any flickering.
Also, you should not store a Graphics
object for later.
Instead, you should draw on e.Graphics
in the Paint
handler.
这篇关于我怎么能借鉴面板,因此不眨眼?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文