On Aug 6, 12:11 pm, KWienhold <hedov...@trashmail.netwrote:
On 6 Aug., 09:35, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Aug 5, 10:38 pm, Jesse Houwing <Jesse.houw...@nospam-sogeti.nl>
wrote:
Hello Alexey,
How to make bold part of the text in a Windows.Forms.Label? Thank you.
If you need one part of the label bold and teh second normal you'd have to
plit them up into two (or more) labels as far as I can tell...
Hi Jesse
Actually I would like to know if I can do it in the same label,
without having two or more labels.
Cheers!
As far as I know it is not possible to use different fonts for
different parts of the same label, since it doesn't support anything
like RTF markups or the like.
So either you use two labels (one for the bold part, one for the
other) or you derive your own label class from label and handle the
drawing yourself.
I guess personally I would go with deriving in this case, since the
implementation would consist mostly of pretty basic GDI+ stuff and is
more flexible than always creating two labels.
hth,
Kevin Wienhold- Hide quoted text -
- Show quoted text -
Okay, thanks
I have overrided the OnPaint() method
For single line text a code would be something like this
// show first 10 letters in bold
e.Graphics.DrawString(this.Text.Substring(0,9),
new System.Drawing.Font("Tahoma", 8.0F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((byte) 0)),
new SolidBrush(this.ForeColor), new
Rectangle(this.Padding.Left, this.Padding.Top, this.Width -
this.Padding.Left, this.Height), StringFormat.GenericDefault);
Size sz = new Size(this.ClientSize.Width, Int32.MaxValue);
sz = TextRenderer.MeasureText(this.Text.Substring(0, 9), this.Font,
sz, TextFormatFlags.WordBreak);
e.Graphics.DrawString(this.Text.Substring(10),
new System.Drawing.Font("Tahoma", 8.0F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)0)),
new SolidBrush(this.ForeColor),
this.Padding.Left + sz.Width, this.Padding.Top);