By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,046 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,046 IT Pros & Developers. It's quick & easy.

Diffrent fonts in one label

P: n/a
Hello

I'm using System.Windows.Forms.Label and I want to add some text, where
one or more words are bold or italic.

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.<

I hope someone can tell me how to do this.

Thanks

Roggey

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

You cannot do this.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<Ro****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello

I'm using System.Windows.Forms.Label and I want to add some text, where
one or more words are bold or italic.

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.<

I hope someone can tell me how to do this.

Thanks

Roggey

Nov 17 '05 #2

P: n/a
<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
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.