Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
I have a textbox in windows form named "tblAmount".By default it shows 1.I need when I press the space bar then a specific textbox's (named tblAmount) will show the value 2. If I press spacebar again it shows 3. Please help me.
I have written the following code :
private void Incrementbutton_KeyDown(object sender, KeyEventArgs e)
        {
if (e.KeyCode == Keys.Space)
            {
                
            }
}
Posted
Updated 7-Feb-14 22:10pm
v4
Comments
Prasad Avunoori 6-Feb-14 4:18am    
tblAmount.Text = Convert.ToInt(tblAmount.Text)+1;
BillWoodruff 6-Feb-14 5:38am    
You want the TextBox integer value to increment when the TextBox has focus and is the active Control ? Your code suggests a Button is getting the Key Event.

on textbox3 keydown event

set textbox3.text default value to any integer value

C#
if (e.KeyCode == 32) {
    if (string.IsNullOrEmpty(this.TextBox3.Text)) {
        this.TextBox3.Text = 0;
    }
    this.TextBox3.Text = Convert.ToInt32(this.TextBox3.Text) + 1;
}
 
Share this answer
 
v3
try this within the bracket as suggested by Mr. Prasad Avunoori
tblAmount.Text = Convert.ToInt(tblAmount.Text)+1;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900