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. RichTextBox and SendKeys action

RichTextBox and SendKeys action

Scheduled Pinned Locked Moved C#
question
3 Posts 2 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

    Does anyone of you can tell why the following code: private void HandleKeyPress(object sender, KeyPressEventArgs e) { char c = e.KeyChar; if(c == (short)Keys.Back) { e.Handled = true; SendKeys.Send("{LEFT}"); return; } } works in common textBox but it doesn`t work in richTextBox? In textBox line e.Handled = true; stops the backspace key action and only action after pressing bakcspace key is move the cursor to left (SendKeys.Send("{LEFT}");). In richTextBox it`s taken double action. e.Handled = true; code doesn`t block backspace key action so: 1) first it deletes character (backspace key do it - it isn`t block) 2) second it moves the cursor to left (like SendKeys.Send("{LEFT}"); code do) Can anyone figure out what`s wrong with it?

    I 1 Reply Last reply
    0
    • C conrado7

      Does anyone of you can tell why the following code: private void HandleKeyPress(object sender, KeyPressEventArgs e) { char c = e.KeyChar; if(c == (short)Keys.Back) { e.Handled = true; SendKeys.Send("{LEFT}"); return; } } works in common textBox but it doesn`t work in richTextBox? In textBox line e.Handled = true; stops the backspace key action and only action after pressing bakcspace key is move the cursor to left (SendKeys.Send("{LEFT}");). In richTextBox it`s taken double action. e.Handled = true; code doesn`t block backspace key action so: 1) first it deletes character (backspace key do it - it isn`t block) 2) second it moves the cursor to left (like SendKeys.Send("{LEFT}"); code do) Can anyone figure out what`s wrong with it?

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

      Try this private void richTextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.Equals(Keys.Back)) { e.SuppressKeyPress = true; SendKeys.Send("{LEFT}"); return; } } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.Equals(Keys.Back)) { e.SuppressKeyPress = true; SendKeys.Send("{LEFT}"); return; } }

      C 1 Reply Last reply
      0
      • I IdUnknown

        Try this private void richTextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.Equals(Keys.Back)) { e.SuppressKeyPress = true; SendKeys.Send("{LEFT}"); return; } } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.Equals(Keys.Back)) { e.SuppressKeyPress = true; SendKeys.Send("{LEFT}"); return; } }

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

        It`s working :D Thank you very much :) But code e.SuppressKeyPress = true; I turned into e.Handled = true; :) -- modified at 9:50 Friday 17th March, 2006

        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