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. prevent keypress

prevent keypress

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 3 Posters 1 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    i want to prevet textbox from store characters & numbers in it after some conditional for example if textbox contain "," after 3letters after "," prevent to add any chars to text how?????? ma_refay

    M 1 Reply Last reply
    0
    • L Lost User

      i want to prevet textbox from store characters & numbers in it after some conditional for example if textbox contain "," after 3letters after "," prevent to add any chars to text how?????? ma_refay

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, You need to handle the KeyPressed event or override the OnKeyPessed in your TextBoxControl which inherits from TextBox. there you have to compare the "e.KeyChar" with the "," or ".".

      if (e.KeyChar == ',')
      {
      if(this.Text.IndexOf(',') > -1)
      {
      e.Handled = true; //Will aport the function
      }
      }

      Hope that helps! All the best, Martin

      A 1 Reply Last reply
      0
      • M Martin 0

        Hello, You need to handle the KeyPressed event or override the OnKeyPessed in your TextBoxControl which inherits from TextBox. there you have to compare the "e.KeyChar" with the "," or ".".

        if (e.KeyChar == ',')
        {
        if(this.Text.IndexOf(',') > -1)
        {
        e.Handled = true; //Will aport the function
        }
        }

        Hope that helps! All the best, Martin

        A Offline
        A Offline
        Ashvin Gunga
        wrote on last edited by
        #3

        If you have many different combinations to cater for, then patterns and regular expressions may also help. I think I have once used regular expressions for similar problem in the past...

        Ashvin Gunga

        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