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.............

Recommended Answers

All 10 Replies

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

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
        }

Thank you all for your replies............:)

commented: plz add me +0

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.