Click here to Skip to main content
16,005,038 members
Home / Discussions / C#
   

C#

 
QuestionC#, .NET 1.1 and the WS_DISABLED window style Pin
ssozonoff4-Oct-06 22:35
ssozonoff4-Oct-06 22:35 
Questiongettting table name Pin
saqib824-Oct-06 21:27
saqib824-Oct-06 21:27 
AnswerRe: gettting table name Pin
albCode4-Oct-06 21:40
albCode4-Oct-06 21:40 
GeneralRe: gettting table name Pin
saqib824-Oct-06 21:44
saqib824-Oct-06 21:44 
GeneralRe: gettting table name Pin
albCode4-Oct-06 21:59
albCode4-Oct-06 21:59 
GeneralRe: gettting table name Pin
saqib824-Oct-06 23:37
saqib824-Oct-06 23:37 
QuestionControl Input: Pin
Shahzad.Aslam4-Oct-06 20:34
Shahzad.Aslam4-Oct-06 20:34 
AnswerRe: Control Input: Pin
Stefan Troschuetz4-Oct-06 21:03
Stefan Troschuetz4-Oct-06 21:03 
In case you use .Net 2.0 you can use the MaskedTextBox control.
Otherwise take a look at the following example copied from the MSDN topic of KeyPress event:
// Boolean flag used to determine when a character other than a number is entered.
private bool nonNumberEntered = false;

// Handle the KeyDown event to determine the type of character entered into the control.
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    // Initialize the flag to false.
    nonNumberEntered = false;

    // Determine whether the keystroke is a number from the top of the keyboard.
    if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
    {
        // Determine whether the keystroke is a number from the keypad.
        if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
        {
            // Determine whether the keystroke is a backspace.
            if(e.KeyCode != Keys.Back)
            {
                // A non-numerical keystroke was pressed.
                // Set the flag to true and evaluate in KeyPress event.
                nonNumberEntered = true;
            }
        }
    }
}

// This event occurs after the KeyDown event and can be used to prevent
// characters from entering the control.
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    // Check for the flag being set in the KeyDown event.
    if (nonNumberEntered == true)
    {
        // Stop the character from being entered into the control since it is non-numerical.
        e.Handled = true;
    }
}



"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

www.troschuetz.de

QuestionGetting Path of the Selected List View Item Pin
ravi_12174-Oct-06 20:25
ravi_12174-Oct-06 20:25 
AnswerRe: Getting Path of the Selected List View Item Pin
albCode4-Oct-06 21:20
albCode4-Oct-06 21:20 
GeneralRe: Getting Path of the Selected List View Item Pin
ravi_12174-Oct-06 21:55
ravi_12174-Oct-06 21:55 
QuestionCombining DataTable fields for Combobox (in DataGridView) DisplayMember Pin
drinkingbird4-Oct-06 18:54
drinkingbird4-Oct-06 18:54 
QuestionSystem::Byte, unsigned int and unsigned char? Pin
bankai1234-Oct-06 17:48
bankai1234-Oct-06 17:48 
AnswerRe: System::Byte, unsigned int and unsigned char? Pin
Christian Graus4-Oct-06 18:44
protectorChristian Graus4-Oct-06 18:44 
GeneralRe: System::Byte, unsigned int and unsigned char? Pin
bankai1234-Oct-06 18:51
bankai1234-Oct-06 18:51 
GeneralRe: System::Byte, unsigned int and unsigned char? Pin
Christian Graus4-Oct-06 18:58
protectorChristian Graus4-Oct-06 18:58 
GeneralRe: System::Byte, unsigned int and unsigned char? Pin
Insincere Dave5-Oct-06 4:30
Insincere Dave5-Oct-06 4:30 
Question...Interesting C# issue with XNA Pin
Alaric_4-Oct-06 17:34
professionalAlaric_4-Oct-06 17:34 
AnswerRe: ...Interesting C# issue with XNA Pin
WillemM4-Oct-06 20:15
WillemM4-Oct-06 20:15 
AnswerRe: ...Interesting C# issue with XNA Pin
S. Senthil Kumar4-Oct-06 22:19
S. Senthil Kumar4-Oct-06 22:19 
AnswerRe: ...Interesting C# issue with XNA Pin
eggsovereasy5-Oct-06 4:25
eggsovereasy5-Oct-06 4:25 
QuestionRegular Expression Pin
Imtiaz Murtaza4-Oct-06 16:44
Imtiaz Murtaza4-Oct-06 16:44 
AnswerRe: Regular Expression Pin
Christian Graus4-Oct-06 18:45
protectorChristian Graus4-Oct-06 18:45 
AnswerRe: Regular Expression Pin
Guffa4-Oct-06 23:04
Guffa4-Oct-06 23:04 
AnswerRe: Regular Expression Pin
subrata.jana4-Oct-06 23:24
subrata.jana4-Oct-06 23:24 

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.