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

[QUOTE=DdoubleD;1003170]Add a KeyDown event:
[code=csharp]
private void textBox_KeyDown(object sender, KeyEventArgs e)
{
if (Control.ModifierKeys == Keys.Space)
;//spacebar was pressed
}
[/code][/QUOTE]

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

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

Jump to Post

All 10 Replies

Re: Replace on pressing spacebar in textbox 80 80

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

Re: Replace on pressing spacebar in textbox 80 80

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

Re: Replace on pressing spacebar in textbox 80 80

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
        }
Re: Replace on pressing spacebar in textbox 80 80

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.

Re: Replace on pressing spacebar in textbox 80 80

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
        }
Re: Replace on pressing spacebar in textbox 80 80

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

commented: plz add me +0
Re: Replace on pressing spacebar in textbox 80 80

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

Re: Replace on pressing spacebar in textbox 80 80

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");
}
}
Re: Replace on pressing spacebar in textbox 80 80

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

Re: Replace on pressing spacebar in textbox 80 80

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.