Windows form app add variable to textbox
I made GUI in VC++2008 Win form app template and I dont know how to assign string or int variable to a textbox that I made.There's no variable field in text field properties and no add variable on right click.I haven't found any.
All that I found in Form.h is :
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::TextBox^ textBox6;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox1;
I guess those are just made for panel and are not supposed to be casted into strings or types I need.
This should be an easy question.
Re: Windows form app add variable to textbox
A TextBox has a property of type string called Text. Convert the value you want to display and assigned it to this property. For instance:
Code:
int i = 42;
textBox1->Text = i.ToString();
Re: Windows form app add variable to textbox
Re: Windows form app add variable to textbox
Thanx cilu!
So if I have textbox and user types [email protected] in, I will read that and store it in char * variable like this:
char* emailVar;
emailVar=textBox1->Text.toChar();
??? I gues I missed types cast func???
and second question:
what lib do I need to include to use UpdateData(); ???
Re: Windows form app add variable to textbox
If you decided from some reason to write C++/CLI GUI application, don't mix managed and unmanaged types if this is not necessary. To get a textbox text, use String variable:
String^ s = textBox1->Text;
Windows form doesn't have UpdateData function. You need to get/set Text property for every textbox on the form to emulate MFC UpdateData behavior.
Re: Windows form app add variable to textbox
what confuses me is that as I see it Ill should write all code in button clicked function in Form.h file ???
like this:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
emailTo=this->textBox1->Text;
MessageBox::Show(emailTo,"caption");
char a[]= "kljlkj";
//UpdateData(true);
}
coz when I make new class or write it in main.cpp I can not reference Form or textboxes...???
Re: Windows form app add variable to textbox
C++/CLI designer produces ugly inline code, because the same program works also for C# and VB .NET. There is also Form1.cpp file, which contains only:
#include "Form1.h"
You can move implementation to .cpp file according to general C++ rules.