Beginner with windows form : Adding Two Numbers

Hello,

I started to use windows form application in c++, i got stuck along the line, i can do MessageBox::Show("Hello World c++");, but here i wanted to try something new, assigning functions to buttons to add two numbers. i am ok with console programs so i decided to move over to something new. Here is how my code goes :

1
2
3
4
5
6
7
8
9
#pragma endregion
	    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		this->add();
		add = textBox1 + textBox2;
		MessageBox::Show("Values of the Two Numbers Are :" +add);
		
	             }
	    };
	}


Am i correct ? It is suppose to gather input from the first text box and the second and then add them together, and display in a Messagebox dialog. Please let me know how to go about it.

Waiting for your replies.
Last edited on
Does this code even compile? I don't think you can just add two textBoxes together. You will need to get the string contents of each TextBox, convert to integer, and then add them together.
I do presume you mean something like this

[Code]
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->add();
String ^ strTextBoxContent;
int a;
int b;
Int32::TryParse(textBox1->Text,a);
Int32::TryParse(textBox2->Text,b);
add = a + b;
MessageBox::Show("The value of the two numbers are : "Convert::ToString(add));

}

[/code]

Am right here??
Last edited on
Topic archived. No new replies allowed.