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. Visual Basic
  4. keypress to include the back space

keypress to include the back space

Scheduled Pinned Locked Moved Visual Basic
help
2 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.
  • T Offline
    T Offline
    thefludragon
    wrote on last edited by
    #1

    private sub num_KeyPress (ByVal sender......blah blah....) If e.KeyChar < "0" or e.KeyChar > "9" then e.handled = true end if end sub can someone plz help iam only using the numbers and want to include the backspace button as well...:rolleyes:

    X 1 Reply Last reply
    0
    • T thefludragon

      private sub num_KeyPress (ByVal sender......blah blah....) If e.KeyChar < "0" or e.KeyChar > "9" then e.handled = true end if end sub can someone plz help iam only using the numbers and want to include the backspace button as well...:rolleyes:

      X Offline
      X Offline
      Xint0
      wrote on last edited by
      #2

      Try this:

      ...
      If (e.KeyChar < '0' Or e.KeyChar > '9') And e.KeyChar <> '\b' Then
      ...

      Additionally if using .NET 2.0 probably it would be better if you used PreviewKeyDown event:

      Private Sub num_PreviewKeyDown(ByVal sender As Object, e As PreviewKeyDownEventArgs)
      e.IsInputKey = ((e.KeyCode = Keys.Back) And (e.Modifiers = 0)) Or ((e.KeyCode >= Keys.D0 Or e.KeyCode <= D9 Or e.KeyCode >= Keys.NumPad0 Or e.KeyCode <= Keys.NumPad9) And (e.Modifiers = 0))
      End Sub

      This way you can handle key combinations like Alt + 0, Ctrl + Backspace, etc. If using .NET 1.1 then use KeyDown to set a flag and check the flag value on the KeyPress event to set the Handled property.

      - Xint0

      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