我有UserControl:Panel。当我添加到Form自己的UserControl。 UserControl.Anchor =左|右|上|下。当我调整窗体矩形的大小时闪烁。怎么能让它不眨眼?
public partial class UserControl1 : Panel
{
public UserControl1()
{
InitializeComponent();
this.ResizeRedraw = true;
}
private void UserControl1_Paint(object sender, PaintEventArgs e)
{
using (Graphics g = this.CreateGraphics())
{
Pen pen = new Pen(Color.Black, 1);
Brush brush = new SolidBrush(Color.Black);
g.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1);
pen.Dispose();
}
}
}
答案 0 :(得分:2)
你可以做很多事情来减少闪烁:
答案 1 :(得分:1)
尝试设置doubleBuffered = true
,您不必在疼痛事件中创建图形对象。你可以从事件args那里得到它。您必须确保在绘画事件中执行最少量的任务。
public partial class UserControl1 : Panel
{
public UserControl1()
{
InitializeComponent();
this.ResizeRedraw = true;
this.DoubleBuffered = true;
}
private void UserControl1_Paint(object sender, PaintEventArgs e)
{
var g = e.Graphics;
Pen pen = new Pen(Color.Black, 1);
Brush brush = new SolidBrush(Color.Black);
g.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1);
}
}