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. SendKeys in C#

SendKeys in C#

Scheduled Pinned Locked Moved C#
csharphelpquestion
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

    I want in my RichTextBox this action to do: Backspace key takes the same action like left arrow key. Speaking generally I don`t want to delete characters by backspace key inside the textBox field unless it is the last character. This code works in TextBox (do the action which I want) but unfortunatelly doesn`t work in RichTextBox. private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { char c = e.KeyChar; int start = textBox1.SelectionStart; int lenght = textBox1.Text.Length; if(c == (short)Keys.Back && start!=lenght) { e.Handled = true; SendKeys.Send("{LEFT}"); return; } } Can anyone help me?

    C 1 Reply Last reply
    0
    • C conrado7

      I want in my RichTextBox this action to do: Backspace key takes the same action like left arrow key. Speaking generally I don`t want to delete characters by backspace key inside the textBox field unless it is the last character. This code works in TextBox (do the action which I want) but unfortunatelly doesn`t work in RichTextBox. private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { char c = e.KeyChar; int start = textBox1.SelectionStart; int lenght = textBox1.Text.Length; if(c == (short)Keys.Back && start!=lenght) { e.Handled = true; SendKeys.Send("{LEFT}"); return; } } Can anyone help me?

      C Offline
      C Offline
      CWIZO
      wrote on last edited by
      #2

      Describe "how it is not working". Do you get a error or what? And aI think making this kind of behaviour is bad. There are standards and I hope you have a really god reason for doing this... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

      C 1 Reply Last reply
      0
      • C CWIZO

        Describe "how it is not working". Do you get a error or what? And aI think making this kind of behaviour is bad. There are standards and I hope you have a really god reason for doing this... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

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

        You asked me why it doesn`t work. It takes two action in the same time. First it deletes charakters (so backspace key works like should work), second it moves cursor to left like I want. In textBox works only second action which exactly I want. In richTextBox work both of them. e.Handled = true; code should make a backspace key action not allowed. Why is that? I need this action in my richTextBox to validate text which I enter to this.

        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