G
Guest
Hi,
I am using Graphics.DrawString in the paint handler of a label.
The text comes up and behaves as expected on all events such as resize of
the lable control.
The problem is when i move a messagebox/ another application( say notepad )
across the lable.
In this case a clean repaint of the text fails to appear. The text gets
drawn erratically or altogether disappears.
What could i be missing out on in this code.
I tried inheriting from System.Windows.Forms.Label and overriding the
onpaint method with same results. I had also tried
having the usercontrol as UserControlStyles.UserPaint.
I was trying to avoid having to create the Graphics object for the lable in
the main form as this is not advisable; but i
tried that also with even worse results.
Any help to get me have the paint handler working properly would be greatly
appreciated.
Regards,
//code snippet
private void lblMessage_Paint(object sender, PaintEventArgs e)
{
if( lblMessage.Text != "" )
lblMessage.Text = "";
Graphics g = e.Graphics;// Graphics.FromHwnd( this.Handle );
//g.SmoothingMode = SmoothingMode.AntiAlias;
StringFormat sf = new StringFormat();
sf.Trimming = StringTrimming.EllipsisCharacter;
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
sf.FormatFlags = StringFormatFlags.LineLimit |
StringFormatFlags.FitBlackBox |
StringFormatFlags.NoClip
;
g.DrawString (
strText,
this.Font,
Brushes.Black,
new RectangleF(
g.VisibleClipBounds.Location,
g.VisibleClipBounds.Size),
sf );
}
I am using Graphics.DrawString in the paint handler of a label.
The text comes up and behaves as expected on all events such as resize of
the lable control.
The problem is when i move a messagebox/ another application( say notepad )
across the lable.
In this case a clean repaint of the text fails to appear. The text gets
drawn erratically or altogether disappears.
What could i be missing out on in this code.
I tried inheriting from System.Windows.Forms.Label and overriding the
onpaint method with same results. I had also tried
having the usercontrol as UserControlStyles.UserPaint.
I was trying to avoid having to create the Graphics object for the lable in
the main form as this is not advisable; but i
tried that also with even worse results.
Any help to get me have the paint handler working properly would be greatly
appreciated.
Regards,
//code snippet
private void lblMessage_Paint(object sender, PaintEventArgs e)
{
if( lblMessage.Text != "" )
lblMessage.Text = "";
Graphics g = e.Graphics;// Graphics.FromHwnd( this.Handle );
//g.SmoothingMode = SmoothingMode.AntiAlias;
StringFormat sf = new StringFormat();
sf.Trimming = StringTrimming.EllipsisCharacter;
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
sf.FormatFlags = StringFormatFlags.LineLimit |
StringFormatFlags.FitBlackBox |
StringFormatFlags.NoClip
;
g.DrawString (
strText,
this.Font,
Brushes.Black,
new RectangleF(
g.VisibleClipBounds.Location,
g.VisibleClipBounds.Size),
sf );
}