Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. rich textbox

rich textbox

Scheduled Pinned Locked Moved C#
question
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    surfman19
    wrote on last edited by
    #1

    hi, the text in the rich textbox is underlined! when i enter a key in the textbox i want to have FontStyle.Regular: private void textBox_Receivers_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { textBox_Receivers.SelectionStart = 0; textBox_Receivers.SelectionLength = textBox_Receivers.ToString().Length; textBox_Receivers.SelectionFont = new Font("Arial",8,FontStyle.Regular); } but when i enter only the one char (the one which i pressed) is in the textbox...why, the other text is cleared!? whats wrong? cu -- modified at 16:31 Tuesday 30th August, 2005

    I 1 Reply Last reply
    0
    • S surfman19

      hi, the text in the rich textbox is underlined! when i enter a key in the textbox i want to have FontStyle.Regular: private void textBox_Receivers_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { textBox_Receivers.SelectionStart = 0; textBox_Receivers.SelectionLength = textBox_Receivers.ToString().Length; textBox_Receivers.SelectionFont = new Font("Arial",8,FontStyle.Regular); } but when i enter only the one char (the one which i pressed) is in the textbox...why, the other text is cleared!? whats wrong? cu -- modified at 16:31 Tuesday 30th August, 2005

      I Offline
      I Offline
      if_mel_yes_else_no
      wrote on last edited by
      #2

      The text box is doing exactly what all text boxes do when all the text is selected and you insert a letter. It takes the selected text and replaces it whith the new letter. You really shouldn't be surprised by your results. If you want to change the font and attach the new letter, then you need to clear your selected text before you leave the method.

      S 1 Reply Last reply
      0
      • I if_mel_yes_else_no

        The text box is doing exactly what all text boxes do when all the text is selected and you insert a letter. It takes the selected text and replaces it whith the new letter. You really shouldn't be surprised by your results. If you want to change the font and attach the new letter, then you need to clear your selected text before you leave the method.

        S Offline
        S Offline
        surfman19
        wrote on last edited by
        #3

        how?

        I 1 Reply Last reply
        0
        • S surfman19

          how?

          I Offline
          I Offline
          if_mel_yes_else_no
          wrote on last edited by
          #4

          SelectionLength = 0; That's the first thing that came to my mind. There are also arguments in the 'e' parameter that you can use. Cancel pretends the keydown never happend, sometimes called Suppress.

          S 1 Reply Last reply
          0
          • I if_mel_yes_else_no

            SelectionLength = 0; That's the first thing that came to my mind. There are also arguments in the 'e' parameter that you can use. Cancel pretends the keydown never happend, sometimes called Suppress.

            S Offline
            S Offline
            surfman19
            wrote on last edited by
            #5

            private void textBox_Receivers_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { textBox_Receivers.SelectionStart = 0; textBox_Receivers.SelectionLength = textBox_Receivers.Text.Length; textBox_Receivers.SelectionFont = new Font("Arial",8,FontStyle.Regular); textBox_Receivers.SelectionLength = 0; } doesn't work...hm cu

            I 1 Reply Last reply
            0
            • S surfman19

              private void textBox_Receivers_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { textBox_Receivers.SelectionStart = 0; textBox_Receivers.SelectionLength = textBox_Receivers.Text.Length; textBox_Receivers.SelectionFont = new Font("Arial",8,FontStyle.Regular); textBox_Receivers.SelectionLength = 0; } doesn't work...hm cu

              I Offline
              I Offline
              if_mel_yes_else_no
              wrote on last edited by
              #6

              richTextBox1.SelectionStart = 0; richTextBox1.SelectionLength = richTextBox1.Text.Length; richTextBox1.SelectionFont = new Font("Arial", 8, FontStyle.Bold); richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.SelectionLength = 0; This works fine when I do it.

              S 1 Reply Last reply
              0
              • I if_mel_yes_else_no

                richTextBox1.SelectionStart = 0; richTextBox1.SelectionLength = richTextBox1.Text.Length; richTextBox1.SelectionFont = new Font("Arial", 8, FontStyle.Bold); richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.SelectionLength = 0; This works fine when I do it.

                S Offline
                S Offline
                surfman19
                wrote on last edited by
                #7

                hi, thx perfect, but i have a problem if i select the whole text in the richtextbox and press clear or backspace then the whole text isn't cleared...hmmm!? but i think i also can do that with Rtf, i mean that with underline...? how? i saw: textBox_Receivers.Rtf ... by the time i like c# *hehe* cu

                I 1 Reply Last reply
                0
                • S surfman19

                  hi, thx perfect, but i have a problem if i select the whole text in the richtextbox and press clear or backspace then the whole text isn't cleared...hmmm!? but i think i also can do that with Rtf, i mean that with underline...? how? i saw: textBox_Receivers.Rtf ... by the time i like c# *hehe* cu

                  I Offline
                  I Offline
                  if_mel_yes_else_no
                  wrote on last edited by
                  #8

                  Rtf is just the same text but with the formatting codes included. You would never want to set the font on your Rtf. The codes will never be seen. If you're asking how to do underline, it's part of the FontStyle just like Regular and Bold.

                  A 1 Reply Last reply
                  0
                  • I if_mel_yes_else_no

                    Rtf is just the same text but with the formatting codes included. You would never want to set the font on your Rtf. The codes will never be seen. If you're asking how to do underline, it's part of the FontStyle just like Regular and Bold.

                    A Offline
                    A Offline
                    Anonymous
                    wrote on last edited by
                    #9

                    if i select all the text in the richtextbox and if i press clear or backspace then all the text isn't cleared...hmmm!? why? cu

                    A 1 Reply Last reply
                    0
                    • A Anonymous

                      if i select all the text in the richtextbox and if i press clear or backspace then all the text isn't cleared...hmmm!? why? cu

                      A Offline
                      A Offline
                      Anonymous
                      wrote on last edited by
                      #10

                      Come on, that one is pretty obvious don't you think?

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups