Diffrent fonts in one label

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roggey@gmail.com

    #1

    Diffrent fonts in one label

    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

  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: Diffrent fonts in one label

    Hi,

    You cannot do this.

    Cheers,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation


    <Roggey@gmail.c om> wrote in message
    news:1115209419 .278617.299330@ g14g2000cwa.goo glegroups.com.. .[color=blue]
    > 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
    >[/color]


    Comment

    • Bjorn Abelli

      #3
      Re: Diffrent fonts in one label

      <Roggey@gmail.c om> wrote...
      [color=blue][color=green]
      >> I'm using System.Windows. Forms.Label and I want to add some text, where
      >> one or more words are bold or italic.[/color][/color]

      Not with the regular Label...
      [color=blue][color=green]
      >> 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.[/color][/color]

      You have possibly seen that mentioned for the Java JLabel...
      [color=blue][color=green]
      >> I hope someone can tell me how to do this.[/color][/color]

      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.RichTextB ox
      {
      public RTFLabel()
      {
      // Note! This control can't take "Transparen t" as BackColor,
      // So you'll have to make something of this...

      this.BackColor = System.Drawing. SystemColors.In activeBorder;
      this.BorderStyl e = System.Windows. Forms.BorderSty le.None;
      this.ReadOnly = true;
      }

      public void Append(string text, Font f)
      {
      int length = text.Length;
      int start = this.Text.Lengt h;
      this.AppendText (text);
      this.Select(sta rt, length);
      this.SelectionF ont = f;
      this.Select(0,0 );
      }

      public void Append(string text, FontStyle fs)
      {
      Font f = new Font(this.Font, fs);
      this.Append(tex t, f);
      }

      public void AppendRegular(s tring text)
      {
      this.Append(tex t, FontStyle.Regul ar);
      }
      public void AppendBold(stri ng text)
      {
      this.Append(tex t, FontStyle.Bold) ;
      }
      public void AppendItalic(st ring text)
      {
      this.Append(tex t, FontStyle.Itali c);
      }
      public void AppendUnderline (string text)
      {
      this.Append(tex t, FontStyle.Under line);
      }

      public void AppendStrikeout (string text)
      {
      this.Append(tex t, FontStyle.Strik eout);
      }
      }
      -------------

      So, you can use this instead of the regular Label...

      // Bjorn A


      Comment

      Working...