FILEDRAW: Read a File of Graphic Commands to Create a Graphic Image
1. Come to class as there may be corrections, changes and additions.
2. Code for READABILITY
3. Follow these directions to create a C# WINDOWS program.
4. Follow these directions to SUBMIT a folder called "FILEDRAW" to your class account
Includes the use of files, loops, if statements and methods.
Program before executing
Program (90% grade): Data file for this image (90 lines: 5C,9R,4E).
Program (90% grade) after reading large file and creating image
Program (100% grade) reading same file and showing stats.
frmMain in Solution Explorer
panDraw: Create a panel that is 500 by 500 (Size property: 500,500)
- created by clicking on the controls in the designer
- created by creating your own method (optional - extra)
(just type in the method OR Highlight Code / left margin/quick action/extract)
WriteText(int rct, int ell, int col)
Read a file that will have the following structure:
Command (R,E,C) followed by 4 integer numbers.
R means rectangle
10 means x location 10
20 means y location 20
50 means width 50
60 means height 60
E means ellipse
20 means x location 20
30 means y location 30
90 means width 90
110 means height 110
C means color
100 means a 100
200 means r 200
150 means g 150
160 means b 160
Sample data file
Small data file Large data file
FILE MUST BE CALLED 'DRAW.TXT'
To add to project:
right-click on the project
change name to "DRAW.TXT"
change property - copy to output - always
. Declare at class level:
Brush drawing object
StreamReader file reader object
. frmMain Load
create graphics object on panDraw
focus on panDraw
. Read File and Create Image button click
File.OpenText("DRAW.TXT") (FILE MUST BE CALLED 'DRAW.TXT')
loop while not at end of stream
read from file
Rectangle - use numbers to create rectangle
else if E
Ellipse - use numbers to create ellipse
else if C
SetColor - use numbers to create new brush
. Clear button
clears panel where graphics object has been created
. Keep track of stats and write stats to panDraw using
DrawString( 3 parameters ) method that you create - must pass in parameters
Font myFont = new Font("Consolas", 14);
gr.DrawString("Rectangle:" + r.ToString(), myFont, Brushes.Blue, 10, 380);
-command - text to display - font - brush -x -y