202: DRAW

Create a program that draws rectangles and ellipses.

1. Come to class as there may be corrections, changes and additions.   Significant late penalty.
2. Follow these directions to create a C# Windows program.  
3. Code for Readability! (guidelines)
4. Follow these directions to SUBMIT a folder called "DRAW" (name of the project)
5. Grading Sheet.

USER INTERFACE (9 controls) =========================== frmDraw (Form) txtIn (TextBox) btnSquares*, btnEllipses*, btnClear*, btnExit* (Button) radWhite, radGray (RadioButton) panDraw (Panel) * - write code for click event for this control Form (frmDraw.cs in solution Explorer) should have the title bar = YOUR LAST NAME (may assign in designer) CODE ================================= Panel (panDraw) will be where all drawing takes place Preliminary code - declare fields (see example code) Random rnd = new Random(); Graphics gr; Brush br; Pen p; (optional) - set up graphics environment in frmDraw_Load() gr = panDraw.CreateGraphics(); TextBox (txtIn) which will allow user to specify integer # of Rectangles / Ellipses - make .Text default value => 5 Use function we built ibn class to generate random colors // generate a random color and return it to caller private Color getColor() { int a = rnd.Next(0, 256); int r = rnd.Next(0, 256); int g = rnd.Next(0, 256); int b = rnd.Next(0, 256); return Color.FromArgb(a, r, g, b); } // can be called anywhere // get random color for our new paint brush br = new SolidBrush( getColor() ); Button to draw random rectangles in a loop (btnSquares) - click event will draw on panel - loop n times get n from textbox - protect with try-catch create brush with random color br = new SolidBrush(Color. ?(some color) ); create pen p = new Pen(Color.Black); draw rectangle of random size at random location gr.FillRectangle( brush, x, y, w, h ); gr.DrawRectangle( pen, x, y, w, h ); (optional) Button to draw random ellipses in a loop (btnEllipses) - click event will draw on panel - loop n times get n from textbox - protect with try-catch create brush with random color br = new SolidBrush(Color. ?(some color) ); draw rectangle of random size at random location gr.FillEllipse( brush, x, y, w, h); Button (btnClear) that will clear the textboxes and reset the focus to frmDraw - uses Radio Buttons ( radWhite, radGray ) to determine which color to use for background. radxxx.Checked is true if selected or false if not selected make one button the default (set .Checked => true in designer) Button to Exit (btnExit) - get confirmation! - see Exit Button - with if example code Comment the code (guidelines) Use good object naming Use good variable naming Format with goood spacing and alignment

CHALLENGE CODE (bonus: candy) ================================= WASD keys act as etch-a-sketch (not case sensitive) Draw on same panel (panDraw) MUST set "keyPreview" property on form to true! Put focus on panel Keep track of x, y position so you know where to draw... Write code for form "KeyDown" event - check e.Keycode [ if (e.KeyCode == Keys.A) ] - create a 1 x 1 rectangle at the x, y location after adjusting x,y in proper direction


CHALLENGE CODE 2 (bonus: more candy) =================================== make entire form slowly fade away and then slowly re-appear not TOO slow - i'm impatient...