i want to know try n catch code which i can use for space bar
during entering user name

Recommended Answers

All 4 Replies

i want to know try n catch code which i can use for space bar
during entering user name

Clearly explain what do you want to do..................

i want to know try n catch code which i can use for space bar
during entering user name

Well i already give you that try and catch code for this.......
You can simply use that try and catch code like this:

try
{
code for spacebar...........
..........
..........
catch
{
MessageBox.show("");
}
}

You don't need to use a try/catch block to do this. Capture the TextBox.KeyPress event for each textbox (username/password) to prevent a space character from being entered:

// This event occurs after the KeyDown event and can be used to prevent
        // characters from entering the control.
        
        // Use this to wire the event in the forms constructor or using the VS designer...
        //this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);

        // event handler...
        private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Space)
            {
                // Stop the character from being entered into the control...
                e.Handled = true;
            }
        }

If you want the user to be notified the character is not allowed, you can place a MessageBox call above in the block that handles the space character.

You don't need to use a try/catch block to do this. Capture the TextBox.KeyPress event for each textbox (username/password) to prevent a space character from being entered:

// This event occurs after the KeyDown event and can be used to prevent
        // characters from entering the control.
        
        // Use this to wire the event in the forms constructor or using the VS designer...
        //this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);

        // event handler...
        private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Space)
            {
                // Stop the character from being entered into the control...
                e.Handled = true;
            }
        }

If you want the user to be notified the character is not allowed, you can place a MessageBox call above in the block that handles the space character.

thanks me try n then reply working succesful or not

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.