I have UserControl : Panel. When I add to Form own UserControl. UserControl.Anchor = Left|Right|Top|Bottom. When I resize Form Rectangle is blinking. How can you make that do not blink?
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();
}
}
}
There are many things you can do to reduce flicker:
Try set doubleBuffered = true
and you do not have to create graphics object in pain event. you can get that from the event args. You have to make sure you do minimum amount of task in a paint event.
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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.