C
chris-s
I've created a basic clickable label derived from
System.Windows.Forms.Control which works fine, BUT, I want to use it
in a situation where it will be 'scrolled' around the screen and this
is where it goes wrong, the 'OnPaint' event is not doing the
background so it ends up being 'smeared' rather than cleanly
displayed.
Below is the 'OnPaint' code, what do I need to do to ensure it is
'cleanly' re-painted?
protected override void OnPaint(PaintEventArgs pe)
{
Graphics gr = pe.Graphics;
base.BackColor = ViewerColors.ViewerBackColor;
if (Autosize)
{
SizeF size = gr.MeasureString(this.Text.ToUpper(),
this.Font);
this.Width = (int)size.Width;
}
else
this.Width = this.Parent.Width - (this.Left +
4);
Color textColor = ForeColor;
SolidBrush b = new SolidBrush(textColor);
gr.DrawString(Text, Font, b, 0, 0);
b.Dispose();
}
Chris
System.Windows.Forms.Control which works fine, BUT, I want to use it
in a situation where it will be 'scrolled' around the screen and this
is where it goes wrong, the 'OnPaint' event is not doing the
background so it ends up being 'smeared' rather than cleanly
displayed.
Below is the 'OnPaint' code, what do I need to do to ensure it is
'cleanly' re-painted?
protected override void OnPaint(PaintEventArgs pe)
{
Graphics gr = pe.Graphics;
base.BackColor = ViewerColors.ViewerBackColor;
if (Autosize)
{
SizeF size = gr.MeasureString(this.Text.ToUpper(),
this.Font);
this.Width = (int)size.Width;
}
else
this.Width = this.Parent.Width - (this.Left +
4);
Color textColor = ForeColor;
SolidBrush b = new SolidBrush(textColor);
gr.DrawString(Text, Font, b, 0, 0);
b.Dispose();
}
Chris