Visual C++ 2005 Express Edition (or later) or Visual Studio 2005 Professional (or later) needed for this Tutorial. The requirements that are needed to run this program are the minimal requirements to run Visual Studio 2005 Professional, Windows XP (w/SP2) or later needed.
This code demonstrates how to display the contents of a text box in a label using a single variable. This is simple C++. A more basic knowledge of C++ is required, or at least an extensive knowledge of Visual Basic (or another Visual Studio programming language) will be a great asset, so that you will understand the basics of Window's Forms and understand why some of these functions work.
Before you start a new project you'll want to enable line numbers and to display some more advanced options (don't worry if you don't understand all of the options I tell you to select). First, we're going to enable the line numbers. I don't remember the exact steps to take in the Visual C++ Express to show line numbers, I'm using Visual Studio instead.
In the File menu click > Tools > Options. A window will pop up. Click the + sign beside Text Editor on the left hand side of the window, then click "All Languages." There is a section close to the bottom of the right hand side that has the caption above some options that says "Display," click on the check box beside "Line numbers."
Simple enough, right? Anyways, now we're going to choose some of the options that Visual Studio (Visual C++ Expres) uses to help you use their IDE more efficiently. Click the + sign beside "Projects and Solutions", then click "General." Don't change the locations for Projects, Project Templates, or Item Templates, instead you're going to make sure all of the check boxes below those three locations are checked. Once all of those check boxes are checked. Click "Ok" at the bottom of the Options window and close Visual Studio (or Visual C++ Express). Then, start Visual Studio (or Visual C++ Express) again. Now we're ready to make our first Windows Forms Application!
Start a New Project in Visual C++ Express, or Visual Studio (and select C++ as the programming language). Click on "CLR," then choose Windows Forms Application from the list that you see (which will be minimal in the Express edition). Name the project whatever you want to name it. I usually name it something meaningful to describe the purpose that this project is intended.
There two sections with text boxes: name and solution. For the name put"Windows Form: Simple C++ Project" and for the solution put "Windows Form: Simple C++ SOlution," then you're ready to start coding your first Windows Forms Application!
The first thing you want to do now, after everything has loaded, is change some of the properties of the Window's Form. Single-click on the form. This is the Design area. On the right hand side of the screen you should see a Solution Explorer and a properties window. On the left side you should see a Toolbox. If you do not, Click View > Solution Explorer. Next, click View > Other Windows > Property Manager. Finally, click View > Toolbox.
In the properties manager, click AZ, this changes from category view to Alphabetical view. To me, this makes the properties so much easier to find. Now, change the following properties to the values that you see:
Font: MS Sans Serif, 12pt
StartPosition: Center
Text: Simple C++ In A Windows Form!
Now, we're going to use a few items from the Toolbox. Pull three labels to the Windows Form. Pull three buttons to the Windows Form. Pull a single Text box to the windows Form. Now, we're going to edit the properties of the controls and place each of the controls in a specific place to make a nice looking GUI (or as close to nice looking as possible)!
Label1 (General Title Label)
Name: xTitleLabel
Font: MS Sans Serif, 16pt, bold
Pull this label to the top of the form. Click on Format > Center in Form > Horizontally.
Label2 (Describes the purpose for the Text box)
Name: xTBoxLabel
Text: Displayed Text
Somewhere close to the top of the form, put this closer to the left hand side of the Form. Don't worry about specifics right now. You can edit the positions of all of your controls later.
Textbox1 (This is the place will contain the text you're going to display in a label)
Name: xContentTextBox
Pull this up beside xTBoxLabel. You can make your alignment's perfect later.
Label3:
Name: xDisplayLabel
Text: (erase label3 from the text area and leave this text blank)
button1:
Name: xDisplayButton
Size: 75,26
Text: &Display (The & makes the D appear to be underlined, it creates an Alt + D function that allows for quick clicking)
button2:
Name: xClearButton
Text: C&lear
button3:
Name: xExitButton
Text: E&xit
Now, click the Display button. Now, push and hold the CTRL button as you click the other two buttons. Next, you're going to click Format > Make Same Size > Both.
Now, click the Display button. Now, push and hold the CTRL button as you click the other two buttons. Next, you're going to click Format > Make Same Size > Both. Click on another control in the form to clear the selection of all three buttons. Now, pull all three buttons close together. Select all three buttons, Click > Format > Center in Form > Horizontally. With all three buttons selected, pull the buttons close to the bottom of the form.
Before we code a working Windows Forms Application, I'm going to show you the code that you should NOT edit, unless you know what you're doing. In the Solution Explorer, click Form1.h (in the headers section) and above that you should see a couple of buttons on the toolbar one is for Design view and the other is for code view. Click code view, you should see something similar to this:
cont. next post