Bachus
1/13/2005 7:51:00 PM
Hi,
I have a form on which I want to place elliptic shaped controls. Next I want
to move these controls. Everything works fine when there is less than ten
controls but when I have a lot of them (about 100) my controls are redrawing
very slow. But if i use normal shaped control it works fine.
I created shaped control by overriding Paint method, I also added some
styles to accelerate drawing but still it is too slow:
public class ShapedControl : System.Windows.Forms.UserControl
{.....
public ShapedControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitializeComponent call
BackColor = Color.Black;
this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer,
true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
System.Drawing.Drawing2D.GraphicsPath path = new
System.Drawing.Drawing2D.GraphicsPath();
path.AddEllipse(0, 0, this.Width, this.Height);
Region = new Region(path);
}
....
}
To make a comparision I created a standard shape control and draw an ellipse
on it in Paint method:
public NonShapedControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitializeComponent call
BackColor = Color.White;
this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer,
true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillEllipse(Brushes.Black, 0, 0, this.Width, this.Height);
}
If you put 100 NonShapedControls and move them all for example on button
click you will see that it works fine.
But if you put 100 ShapedControls it will redraw very slow.
Is there any way to accelerate drawing random shaped controls ?
Thanks,
Adam