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. Number only edit boxes ???

Number only edit boxes ???

Scheduled Pinned Locked Moved C#
question
7 Posts 5 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
    Christian Graus
    wrote on last edited by
    #1

    I've been through the properties a bajillion times - could someone please tell me where Microsoft have hidden the option for an edit box to only accept numbers ? Thanks Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "But there isn't a whole lot out there that pisses me off more than someone leaving my code looking like they leaned on the keyboard and prayed that it would compile. - Jamie Hale, 17/4/2002

    J 1 Reply Last reply
    0
    • C Christian Graus

      I've been through the properties a bajillion times - could someone please tell me where Microsoft have hidden the option for an edit box to only accept numbers ? Thanks Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "But there isn't a whole lot out there that pisses me off more than someone leaving my code looking like they leaned on the keyboard and prayed that it would compile. - Jamie Hale, 17/4/2002

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Its not there :(( There is a masked edit box control here, you can borrow the simple code from that :) It might even be simpler than overrideing Key*, just override IsInputKey/Char and return false for anything but numbers, '.', and ',' then you only need to check for double decimal separators. James Simplicity Rules!

      C D 2 Replies Last reply
      0
      • J James T Johnson

        Its not there :(( There is a masked edit box control here, you can borrow the simple code from that :) It might even be simpler than overrideing Key*, just override IsInputKey/Char and return false for anything but numbers, '.', and ',' then you only need to check for double decimal separators. James Simplicity Rules!

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Thanks. My first thought was to override OnChar and check for myself, but I thought that surely C# couldn't be so pathetic as to leave out edit boxes for numbers only ? I guess I was wrong. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "But there isn't a whole lot out there that pisses me off more than someone leaving my code looking like they leaned on the keyboard and prayed that it would compile. - Jamie Hale, 17/4/2002

        J N M 3 Replies Last reply
        0
        • C Christian Graus

          Thanks. My first thought was to override OnChar and check for myself, but I thought that surely C# couldn't be so pathetic as to leave out edit boxes for numbers only ? I guess I was wrong. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "But there isn't a whole lot out there that pisses me off more than someone leaving my code looking like they leaned on the keyboard and prayed that it would compile. - Jamie Hale, 17/4/2002

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          Christian Graus wrote: I thought that surely C# couldn't be so pathetic Not C#, Windows Forms :-P James :) Simplicity Rules!

          1 Reply Last reply
          0
          • J James T Johnson

            Its not there :(( There is a masked edit box control here, you can borrow the simple code from that :) It might even be simpler than overrideing Key*, just override IsInputKey/Char and return false for anything but numbers, '.', and ',' then you only need to check for double decimal separators. James Simplicity Rules!

            D Offline
            D Offline
            David Wengier
            wrote on last edited by
            #5

            An Extender Provider is even more fun, since you can then attach it to any control that accepts key input. A ComboBox is the most obvious other control that this would be useful for. I just happen to have written one too, but of course, i'm too lazy to do anything about it. :-O -- David Wengier Sonork ID: 100.14177 - Ch00k

            1 Reply Last reply
            0
            • C Christian Graus

              Thanks. My first thought was to override OnChar and check for myself, but I thought that surely C# couldn't be so pathetic as to leave out edit boxes for numbers only ? I guess I was wrong. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "But there isn't a whole lot out there that pisses me off more than someone leaving my code looking like they leaned on the keyboard and prayed that it would compile. - Jamie Hale, 17/4/2002

              N Offline
              N Offline
              Neil Van Note
              wrote on last edited by
              #6

              Another solution, if all you want is a basic TextBox with the ES_NUMBER style applied...

              public class NumericTextBox : System.Windows.Forms.TextBox
              {
              private const int ES_NUMBER = 0x00002000;

              public NumericTextBox()
              {
              }
              
              protected override CreateParams CreateParams 
              {
              	get 
              	{
              		CreateParams createParams = base.CreateParams;
              		createParams.Style |= ES\_NUMBER;
              		return createParams;
              	}
              }
              

              }

              1 Reply Last reply
              0
              • C Christian Graus

                Thanks. My first thought was to override OnChar and check for myself, but I thought that surely C# couldn't be so pathetic as to leave out edit boxes for numbers only ? I guess I was wrong. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "But there isn't a whole lot out there that pisses me off more than someone leaving my code looking like they leaned on the keyboard and prayed that it would compile. - Jamie Hale, 17/4/2002

                M Offline
                M Offline
                Mazdak
                wrote on last edited by
                #7

                I do it in KeyPress. :) Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

                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