Click here to Skip to main content
15,314,303 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I'm trying to change the text of a button when clicked.

With what I have tried, nothing happens when clicked.

What I have tried:

int multiplieurUp1 = 1;

private void btn1x1_Click(object sender, EventArgs e)
            if (multiplieurUp1 == 1)
                multiplieurUp1 = 10;
                btn1x1.Text = "10x";

            if (multiplieurUp1 == 10)
                multiplieurUp1 = 100;
                btn1x1.Text = "100x";

            if (multiplieurUp1 == 100)
                multiplieurUp1 = 1;
                btn1x1.Text = "1x";
Updated 8-Jan-22 5:34am
0x01AA 5-Jan-22 11:55am
A hint: Think about else if ...
[no name] 5-Jan-22 12:44pm
An "else if" would help here, see above

1 solution

Set a breakpoint on the first if statement and run your app.

Then the breakpoint gets hit, the app will stop. Step through the code, line by line, and watch what happens. Hover the mouse over the variables to see their current values.

You either learn to use the debugger or you're going to have a very difficult time writing code.

Your code, as written, will either do nothing with the button text at all, or it will change the text to "1x", every single time.

I'll leave it to you to find out why. I've already told you how to find out.
BillWoodruff 18-Oct-20 9:36am
+5 great to see a response focused on getting the OP to figure it out themselves !

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