Number only edit boxes ???
-
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
-
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
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!
-
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!
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
-
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
Christian Graus wrote: I thought that surely C# couldn't be so pathetic Not C#, Windows Forms :-P James :) Simplicity Rules!
-
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!
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
-
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
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; } }
}
-
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
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