Accepting and Displaying String Inputs (Windows Forms Applications-Microsoft Visual C++ 2008 Express Edition)

Posted by Rey Dacoco in

Visual C++ 2008 accepts and displays input in a manner that is very similar to java. In other words, the method used in accepting string data is different from the method used in accepting numeric data.
To accept a string data, and display it on your desired control, use the following syntax:

this->DestinationObjectName->Property=Convert::ToString (this-> SourceObjectName->Property);
//or simply
this->DestinationObjectName->Property= this-> SourceObjectName->Property;


1. DestinationObjectName is the name of the control where the value will be displayed.
2. SourceObjectName is the name of the control where the value will come from.

Convert::ToString is a method that converts a value inputted in a control to text or string. Using Convert::ToString method in accepting user’s input is not obligatory because all data inputted in a textbox are recognized as string.

A sample application of Convert::ToString method is demonstrated in the following steps:

1. Start MSVC++ Express 2008 by clicking on the Start button, All Programs then clicking on the Microsoft Visual C++ Express Edition Start menu option.

2. Click File>New>Project. The new project dialog box will then come into view.

3. Select Windows Forms Application from the Visual Studio Installed templates, type the project name>Click Ok.
After clicking the Ok button, an IDE suited for windows forms application will then appear containing a form, a toolbox window, and a properties window.

4. Create a user interface similar to the one shown below:

Note: Those texts that appear beside each control are the suggested names for our form controls in this example. If you noticed I am using .Net naming convention in naming controls because it is simpler to use than Leszynski naming convention. To change the value of the name property of each control, just click each individual control then locate the name property in the properties window then assign those descriptive names in our illustration correspondingly.

6. Double-Click the control named OkButton then key-in the following:

//Converts the value inputted in the StringtextBox to string
//Using Convert::ToString method is optional because
//The text entered in a textbox is already interpreted as string
Your code should then appear like this:

private: System::Void OkButton_Click(System::Object^  sender, System::EventArgs^  e) {
this->EnteredLabel->Text= Convert::ToString (this->StringtextBox->Text);
7. Double-click ExitButton, then type this->Close(); between the open and close curly brackets. The this keyword refers to the current form while the Close() method ends the execution of the current form.

Your code should now like this:

private: System::Void ExitButton_Click(System::Object^  sender, System::EventArgs^  e) {
8. Press F5 to execute your application. If you have followed our steps carefully, our sample application should now appear without build errors.


Post a Comment


My photo
I am just a simple man with a simple mind. And this is my simple blog. New Posts will be available soon. Enjoy reading and never stop learning:)

Total Pageviews

Link List


Got questions? You can reach me here: