Things You'll Need:
- Microsoft Visual C# 2008 Express (free)
-
Step 1
Note: This article assumes you have installed Microsoft Visual C# 2008 Express Edition. You may download it for free from here: http://www.microsoft.com/express/download/
Open Microsoft Visual C#. Click on "Project..." to the right of Create in the Recent Projects area of the Start Page.
The New Project window will open. Click on "Windows Forms Application", enter a Name, and click OK.
By default, the only form in the project will be called "Form1" and you will be in Design mode for that form. -
Step 2
Right click on the form and select Properties.
-
Step 3
In the Properties Window, click the button with the lightning bolt. This will show the Events for the form.
-
Step 4
Find the event named Paint and double click the empty cell to it's right. The Paint event is in the Appearance category.
-
Step 5
You will now be in the Form1_Paint method. This method is called any time the form is moved, resized, or restored.
-
Step 6
Add the following code in the Form1_Paint method:
// DrawString(string s, Font font, Brush brush, float x, float y)
e.Graphics.DrawString("C# rocks!", new Font("Arial", 12), Brushes.White, 15, 10);
e.Graphics.DrawString("C# rocks!", new Font("Arial", 12), Brushes.Black, 16, 11);
// FillRectangle(Brush brush, int x, int y, int width, int height)
e.Graphics.FillRectangle(Brushes.White, 15, 35, 50, 50);
e.Graphics.DrawRectangle(Pens.Red, 15, 35, 50, 50);
// FillEllipse(Brush brush, int x, int y, int width, int height)
e.Graphics.FillEllipse(Brushes.White, 15, 100, 50, 50);
e.Graphics.DrawEllipse(Pens.Red, 15, 100, 50, 50);
// FillPolygon(Brush brush, Point[] points)
e.Graphics.FillPolygon(Brushes.White, new Point[3] { new Point(10, 210), new Point(40, 160), new Point(70, 210) });
e.Graphics.DrawPolygon(Pens.Red, new Point[3] { new Point(10, 210), new Point(40, 160), new Point(70, 210) });
First we will draw a string with a shadow effect. The second parameter is a new Font object.
Then we draw various shapes. Note the the Draw methods use Pens and that Fill methods use Brushes.
Also note that the polygon methods take an array of Point objects. Each Point is an X and Y integer that represents the units away from the upper left corner. -
Step 7
Go up to the toolbar and run the program by clicking on the Start Debugging (f5) play button.
NOTE: If you got any kind of error after clicking the play button, you probably made a syntax error when typing the code. Reread the code until you find and correct the error and try again. -
Step 8
The form will take a moment and then pop up. Not bad.












