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. Keypress event

Keypress event

Scheduled Pinned Locked Moved C#
6 Posts 4 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.
  • D Offline
    D Offline
    D i x y
    wrote on last edited by
    #1

    On keypress event i am disallow some of the some of the ascii value like this if (((e.KeyChar >= 91 && e.KeyChar <= 96) || e.KeyChar == 123 || e.KeyChar == 124 || e.KeyChar == 125 || e.KeyChar == 42 || e.KeyChar == 33 || e.KeyChar == 35 || e.KeyChar == 38 || e.KeyChar == 40 || e.KeyChar == 39 || e.KeyChar == 34 || e.KeyChar == 41 || e.KeyChar == 44 || e.KeyChar == 64 || e.KeyChar == 61 || e.KeyChar == 59 || e.KeyChar == 58 || e.KeyChar == 63 || e.KeyChar == 60 || e.KeyChar == 62) != false) { e.Handled = true; } Now hat i want when user press space bar (Ascii value 32) then it will print '~' (Ascii value 126) in place of Ascii 32 if user enter ABCD(SPACE)FGT THEN IT SHOULD PRINT ABCD~FGT

    J P 2 Replies Last reply
    0
    • D D i x y

      On keypress event i am disallow some of the some of the ascii value like this if (((e.KeyChar >= 91 && e.KeyChar <= 96) || e.KeyChar == 123 || e.KeyChar == 124 || e.KeyChar == 125 || e.KeyChar == 42 || e.KeyChar == 33 || e.KeyChar == 35 || e.KeyChar == 38 || e.KeyChar == 40 || e.KeyChar == 39 || e.KeyChar == 34 || e.KeyChar == 41 || e.KeyChar == 44 || e.KeyChar == 64 || e.KeyChar == 61 || e.KeyChar == 59 || e.KeyChar == 58 || e.KeyChar == 63 || e.KeyChar == 60 || e.KeyChar == 62) != false) { e.Handled = true; } Now hat i want when user press space bar (Ascii value 32) then it will print '~' (Ascii value 126) in place of Ascii 32 if user enter ABCD(SPACE)FGT THEN IT SHOULD PRINT ABCD~FGT

      J Offline
      J Offline
      John Ad
      wrote on last edited by
      #2

      Hi, You may use the following code: Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = Keys.Space Then e.SuppressKeyPress = True Dim i As Integer i = Me.TextBox1.SelectionStart Me.TextBox1.Text = Me.TextBox1.Text + "~" Me.TextBox1.SelectionStart = i + 1 End If End Sub Hope this helps.

      Vinay ComponentOne LLC. www.componentone.com

      1 Reply Last reply
      0
      • D D i x y

        On keypress event i am disallow some of the some of the ascii value like this if (((e.KeyChar >= 91 && e.KeyChar <= 96) || e.KeyChar == 123 || e.KeyChar == 124 || e.KeyChar == 125 || e.KeyChar == 42 || e.KeyChar == 33 || e.KeyChar == 35 || e.KeyChar == 38 || e.KeyChar == 40 || e.KeyChar == 39 || e.KeyChar == 34 || e.KeyChar == 41 || e.KeyChar == 44 || e.KeyChar == 64 || e.KeyChar == 61 || e.KeyChar == 59 || e.KeyChar == 58 || e.KeyChar == 63 || e.KeyChar == 60 || e.KeyChar == 62) != false) { e.Handled = true; } Now hat i want when user press space bar (Ascii value 32) then it will print '~' (Ascii value 126) in place of Ascii 32 if user enter ABCD(SPACE)FGT THEN IT SHOULD PRINT ABCD~FGT

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Will this work? if ( e.KeyChar == ' ' ) e.KeyChar = '~' ; And the code you posted looks very difficult to maintain.

        A 1 Reply Last reply
        0
        • P PIEBALDconsult

          Will this work? if ( e.KeyChar == ' ' ) e.KeyChar = '~' ; And the code you posted looks very difficult to maintain.

          A Offline
          A Offline
          Adeel Chaudhry
          wrote on last edited by
          #4

          Well no offense...but the code above is VB ;) ;P

          Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

          P 1 Reply Last reply
          0
          • A Adeel Chaudhry

            Well no offense...but the code above is VB ;) ;P

            Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            No it isn't. Why do you say so? Or do you mean Vinay's response?

            A 1 Reply Last reply
            0
            • P PIEBALDconsult

              No it isn't. Why do you say so? Or do you mean Vinay's response?

              A Offline
              A Offline
              Adeel Chaudhry
              wrote on last edited by
              #6

              second option:

              PIEBALDconsult wrote:

              Vinay's response

              Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

              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