Different colored lines in the same textbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • None

    #1

    Different colored lines in the same textbox

    How do i write lines with different colors in a textbox?
    I've tried using the forecolor property and it just takes the last
    color.
    eg.
    TextBox1.ForeCo lor = Color.Red
    TextBox1.Text = "test" & " "
    TextBox1.ForeCo lor = Color.Purple
    TextBox1.Text &= "test2"

    It prints both test and test2 in purple

  • James Jardine

    #2
    Re: Different colored lines in the same textbox


    "None" <shefsspecial@g mail.com> wrote in message
    news:1143090151 .769446.274120@ v46g2000cwv.goo glegroups.com.. .[color=blue]
    > How do i write lines with different colors in a textbox?
    > I've tried using the forecolor property and it just takes the last
    > color.
    > eg.
    > TextBox1.ForeCo lor = Color.Red
    > TextBox1.Text = "test" & " "
    > TextBox1.ForeCo lor = Color.Purple
    > TextBox1.Text &= "test2"
    >
    > It prints both test and test2 in purple
    >[/color]

    I don't believe this is possible in a default textbox. There are 2 options
    I believe you have..

    1. use an RTF box instead.
    2. Custom Draw your textbox. This would be more work but I think it would
    allow you to set the different colors using the graphics.drawxx xx methods.

    jjardine


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Different colored lines in the same textbox

      "None" <shefsspecial@g mail.com> schrieb:[color=blue]
      > How do i write lines with different colors in a textbox?
      > I've tried using the forecolor property and it just takes the last
      > color.
      > eg.
      > TextBox1.ForeCo lor = Color.Red
      > TextBox1.Text = "test" & " "
      > TextBox1.ForeCo lor = Color.Purple
      > TextBox1.Text &= "test2"
      >
      > It prints both test and test2 in purple[/color]

      You may want to use the RichTextBox control instead of the common textbox.
      The richtextbox' 'SelectionColor ' property can be used to change the color
      of the selected text.

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

      Comment

      Working...