Click here to Skip to main content
14,390,428 members
Rate this:
Please Sign up or sign in to vote.
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 23: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.
Rate this:
Please Sign up or sign in to vote.

Solution 1

on textbox3 keydown event

set textbox3.text default value to any integer value

if (e.KeyCode == 32) {
    if (string.IsNullOrEmpty(this.TextBox3.Text)) {
        this.TextBox3.Text = 0;
    }
    this.TextBox3.Text = Convert.ToInt32(this.TextBox3.Text) + 1;
}
   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 2

try this within the bracket as suggested by Mr. Prasad Avunoori
tblAmount.Text = Convert.ToInt(tblAmount.Text)+1;
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100