<Ro****@gmail.com> wrote...
I'm using System.Windows.Forms.Label and I want to add some text, where
one or more words are bold or italic.
Not with the regular Label...
I tried it with html tags but does not work. Somewhere i did read it
should be done by html tags. I did it like this:
label1.Text="my <b>test</b> string";
In the output i can see the html tags.
You have possibly seen that mentioned for the Java JLabel...
I hope someone can tell me how to do this.
You can construct a Control of your own.
To give you a hint what you can do, here's a speedy hack, inheriting from a
RichTextBox:
class RTFLabel : System.Windows.Forms.RichTextBox
{
public RTFLabel()
{
// Note! This control can't take "Transparent" as BackColor,
// So you'll have to make something of this...
this.BackColor = System.Drawing.SystemColors.InactiveBorder;
this.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.ReadOnly = true;
}
public void Append(string text, Font f)
{
int length = text.Length;
int start = this.Text.Length;
this.AppendText(text);
this.Select(start, length);
this.SelectionFont = f;
this.Select(0,0);
}
public void Append(string text, FontStyle fs)
{
Font f = new Font(this.Font, fs);
this.Append(text, f);
}
public void AppendRegular(string text)
{
this.Append(text, FontStyle.Regular);
}
public void AppendBold(string text)
{
this.Append(text, FontStyle.Bold);
}
public void AppendItalic(string text)
{
this.Append(text, FontStyle.Italic);
}
public void AppendUnderline(string text)
{
this.Append(text, FontStyle.Underline);
}
public void AppendStrikeout(string text)
{
this.Append(text, FontStyle.Strikeout);
}
}
-------------
So, you can use this instead of the regular Label...
// Bjorn A