Mixinf fonts in a TextBox?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zacks@construction-imaging.com

    Mixinf fonts in a TextBox?

    I have a multiline textbox control where I would like to load up with
    something like the following:

    This is Line 1 <- this line is NOT bold
    This is Line 2 <- this line is bold
    This is Line 3 <- this line is NOT bold

    I have attempted to use C# code like the following:

    string part1 = "This is Line 1" + Environment.New Line;
    string part2 = "This is Line 2" + Environment.New Line;
    string part3 = "This is Line 3" + Environment.New Line;

    textbox.Text = part1;
    textbox.Font = new Font(textbox.Fo nt, textbox.Font.St yle |
    FontStyle.Bold) ;
    textbox.AppendT ext(part2);
    textbox.Font = new Font(textbox.Fo nt, textbox.Font.St yle | !
    FontStyle.Bold) ;
    textbox.AppendT ext(part3);

    But the compiler complains that the ! operator cannot appear where it
    is. I know there has to be some simple way to do this, but I just
    haven't been able to find it yet.

    Can anyone help?

    TIA,
  • Peter Morris

    #2
    Re: Mixinf fonts in a TextBox?

    You need to use RichTextBox instead. I'm sure Google will be able to tell
    you what to do with it.


    Comment

    • Tom Dacon

      #3
      Re: Mixinf fonts in a TextBox?

      You won't do it with a TextBox - use a RichTextBox instead.

      Tom Dacon
      Dacon Software Consulting

      <zacks@construc tion-imaging.comwrot e in message
      news:ebc2e37c-d47d-49be-b341-daf078da8cc8@s1 3g2000prd.googl egroups.com...
      >I have a multiline textbox control where I would like to load up with
      something like the following:
      >
      This is Line 1 <- this line is NOT bold
      This is Line 2 <- this line is bold
      This is Line 3 <- this line is NOT bold
      >
      I have attempted to use C# code like the following:
      >
      string part1 = "This is Line 1" + Environment.New Line;
      string part2 = "This is Line 2" + Environment.New Line;
      string part3 = "This is Line 3" + Environment.New Line;
      >
      textbox.Text = part1;
      textbox.Font = new Font(textbox.Fo nt, textbox.Font.St yle |
      FontStyle.Bold) ;
      textbox.AppendT ext(part2);
      textbox.Font = new Font(textbox.Fo nt, textbox.Font.St yle | !
      FontStyle.Bold) ;
      textbox.AppendT ext(part3);
      >
      But the compiler complains that the ! operator cannot appear where it
      is. I know there has to be some simple way to do this, but I just
      haven't been able to find it yet.
      >
      Can anyone help?
      >
      TIA,

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Mixinf fonts in a TextBox?

        <zacks@construc tion-imaging.comschr ieb:
        >I have a multiline textbox control where I would like to load up with
        something like the following:
        >
        This is Line 1 <- this line is NOT bold
        This is Line 2 <- this line is bold
        This is Line 3 <- this line is NOT bold
        >
        I have attempted to use C# code like the following:
        >
        string part1 = "This is Line 1" + Environment.New Line;
        string part2 = "This is Line 2" + Environment.New Line;
        string part3 = "This is Line 3" + Environment.New Line;
        >
        textbox.Text = part1;
        textbox.Font = new Font(textbox.Fo nt, textbox.Font.St yle |
        FontStyle.Bold) ;
        textbox.AppendT ext(part2);
        textbox.Font = new Font(textbox.Fo nt, textbox.Font.St yle | !
        FontStyle.Bold) ;
        textbox.AppendT ext(part3);
        Take a look at the RichTextBox control and its 'Select' method and
        'SelectionFont' property.

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

        Comment

        Working...