simple windows forms program in Microsoft Visual C++ 2008 Express

I am trying to write a simple program in C++ which has Windows forms. The program I use is Microsoft Visual C++ Express 2008. I start with: File/New Project/CLR/Windows Form Application. I put on the form: two text boxes - textBox1 and textBox2 (where two numbers are to be input), one label box label1 (where the sum of these number is to be displayed), and one button button1 (clicking it should generate the output in label1 field).
Of course, I double click the button (in Form1.h [Design*]) and the following code appears:
1
2
3
4
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
	};

I tried to put various set of instructions here but nothing works properly. This is one example of my work:
1
2
3
4
5
6
7
8
9
10
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
char number1 = this->textBox1->Text;
double numb1 = (double) number1;
char number2 = this->textBox2->Text;
double numb2 = (double) number2;
double result = number1 + number2;
char result1 = (char) result;
this->label1->Text = L"The sum = " + result1;	}
};


I cannot find a really basic tutorial or book how to deal with such a situation, so I am asking this question on the forum.
Last edited on
Windows Forms is not C++. It's Managed C++, I think.
check on google - there are various WinForms tutorials. If you need a good book, you can check for downloadable e-books:

Beginning Visual C++ 2008, Ivar Horton, Wrox
PRO Visual C++/CLI and. NET/publisher: Apress

P.S. remember! you should buy this or any other book if you feel that it is worth of it! good authors must be supported :-)

@program

you must know that textBox->Text; is string type
for more info:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.aspx

so you can't put int/double etc into textBox without converting it to string, because the compiler won't recognize it
e.g. double number1 = textBox1->Text; will cause an error

do as follow:
1
2
3
4
5
6
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
{
	double number1 = Convert::ToDouble(textBox1->Text); 
	double number2 = Convert::ToDouble(textBox2->Text);
	label1->Text = "Sum = " + Convert::ToString(number1+number2);
}


Last edited on
Thank you very much for your reply. It helped a lot. Now I learned the logic of programming windows forms in C++/CLI (I thought it was much more complicated). I knew the book "Beginning Visual C++ 2008" but I could not find the proper code there. But of course, I will have to study the C++/CLI more thouroughly to find the answers to some other questions!
Once again, thanks, it was very helpful!
Topic archived. No new replies allowed.