C# .NET Graphics Extra – not testedRequired for assignment 1
What will we be learning?Surface, pen and brushDraw LinesDraw RectanglesDraw PolygonsDraw Text
Basic - Graphics(1) we need to have a Graphics instance (similar to a surface)
BasicDeclareGraphics  mySurface;
BasicCreateGraphics  mySurface;mySurface = this.CreateGraphics();
Basic - Pen(2) To draw lines or outlines of shapes, we need a Pen
Basic - PenDeclarePen pen1;
Basic - PenCreate2 parameters- Color- thicknessPen pen1;pen1 = new Pen(Color.Blue, 1.0f);
Basic - Brush(3) To fill inside shapes, we need a Brush
Basic - BrushDeclareTypes of brushSolidBrushHatchBrushLinearGradientBrushPathGradientBrushTextureBrushSolidBrush brush1;
Basic - BrushCreateSolidBrush brush1;brush1 = new SolidBrush(Color.Green);
Basic - BrushTypes of brushSolidBrushHatchBrushLinearGradientBrushPathGradientBrushTextureBrush
Draw Lines> New Solution: SpfGraphics> Select Form1.cs, select design view> select events and double click “Paint” event
Draw Lines
Draw Lines
Output
Using points & DrawLinesContinue in Form1_Paint
Outputsurface1.DrawLine(pen1, pt1, pt3);surface1.DrawLines(pen1, points);
Draw RectangleContinue in Form1_Paint
Draw Rectangle
Fill ShapeContinue in Form1_Paint
Fill Shape
Draw PolygonContinue in Form1_Paint
Draw Polygon
Draw TextContinue in Form1_Paint
Draw Text
Try it yourself: drawing cross for mousedownVIDEO
Try it yourself!Hint: use the mousedown eventHint: use points (e.X-5, e.Y-5) , (e.X+5, e.Y+5), (e.X+5, e.Y-5) , (e.X-5, e.Y+5)
Possible solution
Draw fix line follow mouse
Draw fix line follow mouseNew project “lineFollowMouse”
Draw fix line follow mouse// Get the mouse position
Demo:  flexi line follow mouseVIDEO
Flexi line follow mouse// Get the mouse position
Demo: Simple pixel drawingVIDEO
Simple pixel drawingNew project: SimplePixelDrawing
Simple pixel drawing
Simple pixel drawing
Simple pixel drawingto continue next page
Simple pixel drawingcontinue from previous page
SummarySurface, pen and brushDraw LinesDraw RectanglesDraw PolygonsDraw Text

Graphics