Don't use e.ClipRectangle, use this.ClientRectangle instead. ClipRectangle
will return the exact area to paint. In other words, it will return only the
portion of the control that is invalidated and needs to be redrawn. However,
you were painting the entire control into this invalidated region. See the
modified code below.
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
if(this.drawGradientBackground)
{
// Set gradient brush.
LinearGradientBrush brush = new
LinearGradientBrush(this.ClientRectangle, this.gradientColorA,
this.gradientColorB, this.gradientMode);
// Draw the gradient background.
e.Graphics.FillRectangle(brush, this.ClientRectangle);
// Dispose.
brush.Dispose();
}
}
protected override void OnPaint(PaintEventArgs e)
{
// If drawOutline is true, draw outline around toolbar.
if(this.drawOutline)
{
// Create pen with outlineColor applied.
Pen outlinePen = new Pen(this.outlineColor, 2);
// Draw outline.
e.Graphics.DrawRectangle(outlinePen, this.ClientRectangle);
// Dispose.
outlinePen.Dispose();
}
// Fires the Paint event.
base.OnPaint(e);
}
--
Tim Wilson
..Net Compact Framework MVP
"CroDude" <di***********@zg.htnet.hr> wrote in message
news:d0**********@news1.xnet.hr...
Thanks for help, but unfortunately that didn't do it.
Every time when I drag some other form above that panel or if I hide child
control there are glitches in the drawing of the panel control.
Here is my drawing code:
protected override void OnPaint(PaintEventArgs e)
{
// If drawOutline is true, draw outline around toolbar
if(this.drawOutline)
{
// Set rectangle for drawing
Rectangle drawRectangle = e.ClipRectangle;
// Create pen with outlineColor applied
Pen outlinePen = new Pen(this.outlineColor, 2);
// Draw outline
e.Graphics.DrawRectangle(outlinePen, drawRectangle.X ,
drawRectangle.Y , drawRectangle.Width , drawRectangle.Height );
}
else
{
base.OnPaint(e);
}
}
and:
protected override void OnPaintBackground(PaintEventArgs e)
{
if(this.drawGradientBackground)
{
// Set gradient brush
LinearGradientBrush brush = new
LinearGradientBrush(e.ClipRectangle, this.gradientColorA, this.gradientColorB, this.gradientMode);
// Draw the gradient background.
e.Graphics.FillRectangle(brush, e.ClipRectangle);
}
else
{
base.OnPaintBackground (e);
}
}