I have made an application in which there are two textboxes such that as I am writing in first textbox ,it automatically appears in second textbox.
Like for enter key we can apply any functionality on enter key press event ...
Is the same thing possible for spacebar key too......
Can anyone help me in this.............

Edited 7 Years Ago by avirag: n/a

you can apply code on key press event............

Edited 7 Years Ago by VibhorG: n/a

Ya well , it can works for all keys, i just want for space key.....

Ya well , it can works for all keys, i just want for space key.....

Add a KeyDown event:

private void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (Control.ModifierKeys == Keys.Space)
                ;//spacebar was pressed
        }

Perhaps I don't understand you very well, but the spacebar, albeit a bit greater than the other keys, is a key like any other key.

Add a KeyDown event:

private void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (Control.ModifierKeys == Keys.Space)
                ;//spacebar was pressed
        }

Sorry, I just realized I compared apples to oranges somewhat.... Try this instead:

private void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Space)
                ;//spacebar was pressed
        }

or, you can also do it this way:

private void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == ' ')
                ;//spacebar was pressed
        }

Ya well , it can works for all keys, i just want for space key.....

plz i am a new user for c# n my asignment is to desighn a login page which i complete but i want when a space bar is enter during entering a username a message display that spaces are not allowed plz tell me how it is possible thank u

plz i am a new user for c# n my asignment is to desighn a login page which i complete but i want when a space bar is enter during entering a username a message display that spaces are not allowed plz tell me how it is possible thank u

Wherever you written your code to not allowing spacebar, there u just handle the error in try catch block..........

try{
// write the code of not allowing spacebar
...............
..............
catch
{
MessageBox.show("Spaces are not allowed");
}
}

Wherever you written your code to not allowing spacebar, there u just handle the error in try catch block..........

try{
// write the code of not allowing spacebar
...............
..............
catch
{
MessageBox.show("Spaces are not allowed");
}
}

thanks but i want to know that code plz u know then tell me ....
n i heard there is a buld in function for spacebar plz u know that function then tell me

thanks but i want to know that code plz u know then tell me ....
n i heard there is a buld in function for spacebar plz u know that function then tell me

This thread is already solved, make a new thread and ask your problem there...........
thankyou

This question has already been answered. Start a new discussion instead.