Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Example of Windows Forms Applications Windows-based application –Win Forms Control structures (selection and repetition) Graphics Read integers from.

Similar presentations


Presentation on theme: "An Example of Windows Forms Applications Windows-based application –Win Forms Control structures (selection and repetition) Graphics Read integers from."— Presentation transcript:

1 An Example of Windows Forms Applications Windows-based application –Win Forms Control structures (selection and repetition) Graphics Read integers from a file Classes Event handling Others

2 Create a form application using Visual C++ Step 0: //Create a Windows Forms application in Visual Studio 2012 –Create an empty Form1 following class web “Useful Links” on “how-to- use …”, http://cs351.cs.ua.edu/F2014/VS2012.htm –do not add stuffs to the empty Form1 –change Form1’s Text to “CS351”: with the “Form1.h[Design]” active, open the “Properties” window, change the existing “Form1” to “CS351” –Add (copy-paste) code from main.cpp to Form1.cpp by first clicking the Form1.cpp from the “Solution Explorer” window to open it; then modifying the namespace to be your project name; –Build and run, make sure it works

3 Cont’d I There are two approaches to try to work out the rest of the sample code, –Approach 1 is a direct copy-paste, –Approach 2 takes each step in class. Step1, Approach 1: –Copy the sample code to the Form1.h (double click Form1 in the [Design], modify the namespace to your project name. –Or, copy the sample code file Form1.h to the project directory (replace the existing file); modify the namespace to your project name. –Prepare a text file control.txt with an integer in it. –Build and run –Change the integer in control.txt, run again.

4 Step1, Approach 2: // read the sample code to help –Open Form1.h, by double clicking Form1 in the [Design] view –Add int choice; to the Form1 class, –Add the code to read an integer from the control.txt file in the Form1’s constructor; add, close to the beginning, to use the System::IO name space. –Add the Form1_Paint event handler to the Form1 class: Go to the [Design] view of Form1, then to the “Properties” window, Right on top, click the icon look like a lightning bolt (the cursor shows “Events”) Find “Paint”, double click (the needed code of the handler function is created, doing nothing) –Copy the body of this function from the part of the sample code (for-loops etc) within the same handler function name. –Prepare a text file control.txt with an integer in it –Build and run –Change the integer in control.txt, run again. Cont’d I

5 Math Functions There is a class called System::Math double radian=Math::PI/180.0; double y=Math::Sin(x);


Download ppt "An Example of Windows Forms Applications Windows-based application –Win Forms Control structures (selection and repetition) Graphics Read integers from."

Similar presentations


Ads by Google