|
-
March 6th, 2010, 03:06 PM
#1
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.
-
March 6th, 2010, 04:24 PM
#2
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();
-
March 6th, 2010, 04:24 PM
#3
Re: Windows form app add variable to textbox
-
March 6th, 2010, 04:46 PM
#4
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(); ???
Last edited by suncica2222; March 6th, 2010 at 04:49 PM.
-
March 7th, 2010, 04:47 AM
#5
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.
-
March 7th, 2010, 05:16 AM
#6
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...???
-
March 7th, 2010, 08:36 AM
#7
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|