How to make a number appearing in a text box after clicking a button?

I am new to this website and quite new to programming.

I am making a calculator in C #, and I would like to know how I will make the number appearing in the text box after clicking the button to press it.

Thanks!

+4
source share
1 answer

You need to add the code to the button event handler:

public void Button1_Click(Object sender, EventArgs e) { TextBox1.Text = "1"; } 

To display string "1" in the text box.

You can also have several text fields on a web page and use:

 public void Button1_Click(Object sender, EventArgs e) { string input1 = txtInput.Text; string input2 = txtInput2.Text; int userInput; int userInput2; int result; Int32.TryParse(input1, out userInput); Int32.TryParse(input2, out userInput2); result = userInput + userInput2; txtAnswer.Text = "The answer is: " result.ToString(); } 

I included the TryParse example, which demonstrates a successful conversion from integers to numbers.

0
source

Source: https://habr.com/ru/post/1501029/


All Articles