Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
GeneralRe: What do you mean ? Pin
Saikek10-Jul-07 22:28
Saikek10-Jul-07 22:28 
GeneralRe: What do you mean ? Pin
Vikram A Punathambekar10-Jul-07 22:33
Vikram A Punathambekar10-Jul-07 22:33 
GeneralRe: What do you mean ? Pin
J4amieC11-Jul-07 0:17
J4amieC11-Jul-07 0:17 
GeneralRe: What do you mean ? Pin
Sathesh Sakthivel11-Jul-07 0:21
Sathesh Sakthivel11-Jul-07 0:21 
QuestionHow to hold up some key on the keyset? Pin
jason_mf10-Jul-07 21:45
jason_mf10-Jul-07 21:45 
AnswerRe: How to hold up some key on the keyset? Pin
Martin#10-Jul-07 22:09
Martin#10-Jul-07 22:09 
GeneralRe: How to hold up some key on the keyset? Pin
jason_mf10-Jul-07 22:49
jason_mf10-Jul-07 22:49 
GeneralRe: How to hold up some key on the keyset? Pin
Martin#10-Jul-07 23:32
Martin#10-Jul-07 23:32 
Hello,

jason_mf wrote:
But it is noneffective.

YEs, sorry you also have to handle KeyPress!

But what I would recommend is inheriting your own NumericTextBox from TextBox.
public class NumericTextBox : System.Windows.Forms.TextBox
{


And override OnKeyPressed and OnKeyDown:
bool keydownHandled; //Flag from OnKeyDown, cause it's easier to validate there

protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
    switch (e.KeyCode)
    {
        case Keys.D0:
        case Keys.D1:
        case Keys.D2:
        case Keys.D3:
        case Keys.D4:
        case Keys.D5:
        case Keys.D6:
        case Keys.D7:
        case Keys.D8:
        case Keys.D9:
        case Keys.NumPad0:
        case Keys.NumPad1:
        case Keys.NumPad2:
        case Keys.NumPad3:
        case Keys.NumPad4:
        case Keys.NumPad5:
        case Keys.NumPad6:
        case Keys.NumPad7:
        case Keys.NumPad8:
        case Keys.NumPad9:
        case Keys.Enter:
            break;
        default:
            e.Handled = true;
            break;
    }
    keydownHandled = e.Handled;
    base.OnKeyDown (e);
}

protected override void OnKeyPress(KeyPressEventArgs e)
{
    e.Handled = keydownHandled;  //flag from OnKeyDown
    base.OnKeyPress (e);
}


For the ENTER Key you can do the handling of KeyDown directly on the Form.

Hope it helps!

P.S.: Don't forget to care about "copy/paste"


All the best,

Martin

GeneralRe: How to hold up some key on the keyset? Pin
Martin#10-Jul-07 23:40
Martin#10-Jul-07 23:40 
QuestionHow to detect IIS contains a server certificate? Pin
fujitsubo10-Jul-07 21:37
fujitsubo10-Jul-07 21:37 
QuestionSearching through an ArrayList Pin
Darkness8410-Jul-07 21:10
Darkness8410-Jul-07 21:10 
AnswerRe: Searching through an ArrayList Pin
Michael Sync10-Jul-07 21:29
Michael Sync10-Jul-07 21:29 
AnswerRe: Searching through an ArrayList Pin
Guffa10-Jul-07 21:49
Guffa10-Jul-07 21:49 
GeneralRe: Searching through an ArrayList Pin
Michael Sync10-Jul-07 22:18
Michael Sync10-Jul-07 22:18 
AnswerRe: Searching through an ArrayList Pin
Darkness8411-Jul-07 19:07
Darkness8411-Jul-07 19:07 
Questionhow to adjust designing part(.aspx)page Pin
srinivassam10-Jul-07 20:52
srinivassam10-Jul-07 20:52 
AnswerRe: how to adjust designing part(.aspx)page Pin
Vikram A Punathambekar10-Jul-07 22:30
Vikram A Punathambekar10-Jul-07 22:30 
QuestionListViewIten RightClick Pin
topksharma198210-Jul-07 20:49
topksharma198210-Jul-07 20:49 
Questionread from serialport problem Pin
supercsharp110-Jul-07 20:29
supercsharp110-Jul-07 20:29 
AnswerRe: read from serialport problem Pin
Hesham Yassin10-Jul-07 22:24
Hesham Yassin10-Jul-07 22:24 
AnswerRe: read from serialport problem Pin
Luc Pattyn10-Jul-07 23:48
sitebuilderLuc Pattyn10-Jul-07 23:48 
QuestionHEX-values Pin
roiter10-Jul-07 20:10
roiter10-Jul-07 20:10 
AnswerRe: HEX-values Pin
Martin#10-Jul-07 20:17
Martin#10-Jul-07 20:17 
GeneralRe: HEX-values Pin
roiter10-Jul-07 20:27
roiter10-Jul-07 20:27 
GeneralRe: HEX-values Pin
Martin#10-Jul-07 20:28
Martin#10-Jul-07 20:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.