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. Formating text in textBox

Formating text in textBox

Scheduled Pinned Locked Moved C#
helpquestion
4 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.
  • C Offline
    C Offline
    conrado7
    wrote on last edited by
    #1

    I want in my textBox enter characters in the following way: private void textBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { int i = this.textBox2.SelectionStart; if(i which is mean that every single character which is entered should replace existing character unless the cursor is on the end of the text. This sample code doesn`t work I want. Speaking gennerally I want in my text Box to replace all characters with new entered unless the cursor is on the end of the text. Can anyone help me? -- modified at 9:54 Wednesday 19th April, 2006

    M T 2 Replies Last reply
    0
    • C conrado7

      I want in my textBox enter characters in the following way: private void textBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { int i = this.textBox2.SelectionStart; if(i which is mean that every single character which is entered should replace existing character unless the cursor is on the end of the text. This sample code doesn`t work I want. Speaking gennerally I want in my text Box to replace all characters with new entered unless the cursor is on the end of the text. Can anyone help me? -- modified at 9:54 Wednesday 19th April, 2006

      M Offline
      M Offline
      MCSD Gandalf
      wrote on last edited by
      #2

      Try replacing your KeyDown code with: private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { int i = this.textBox1.SelectionStart; if (i < this.textBox1.TextLength) { this.textBox1.SelectAll(); } } When I did this, I had a value in the textbox, keyed a value, and it replaced everything in the text box. When I keyed values at the end, it just added it on. I think that's what you wanted.

      C 1 Reply Last reply
      0
      • M MCSD Gandalf

        Try replacing your KeyDown code with: private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { int i = this.textBox1.SelectionStart; if (i < this.textBox1.TextLength) { this.textBox1.SelectAll(); } } When I did this, I had a value in the textbox, keyed a value, and it replaced everything in the text box. When I keyed values at the end, it just added it on. I think that's what you wanted.

        C Offline
        C Offline
        conrado7
        wrote on last edited by
        #3

        I know what you mean, but it isn`t the action I want. I don`t want replace all characters in my textBox but I want replace only that character which is curently selected by the posision of the cursor. For example text: 12345 when the cursor is (for ex.) between 3 and 4 by enter new character a want replace character 4 by new one. This should work like insert key in Microsoft Word. Anyone know the answer?

        1 Reply Last reply
        0
        • C conrado7

          I want in my textBox enter characters in the following way: private void textBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { int i = this.textBox2.SelectionStart; if(i which is mean that every single character which is entered should replace existing character unless the cursor is on the end of the text. This sample code doesn`t work I want. Speaking gennerally I want in my text Box to replace all characters with new entered unless the cursor is on the end of the text. Can anyone help me? -- modified at 9:54 Wednesday 19th April, 2006

          T Offline
          T Offline
          The Nemesis
          wrote on last edited by
          #4

          use the Key_Press event instead of the Key_down event...that should work with the same code..

          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