C# .NET Graphics <br />Extra – not tested<br />Required for assignment 1<br />
What will we be learning?<br />Surface, pen and brush<br />Draw Lines<br />Draw Rectangles<br />Draw Polygons<br />Draw Te...
Basic - Graphics<br />(1) we need to have a Graphics instance (similar to a surface)<br />
Basic<br />Declare<br />Graphics  mySurface;<br />
Basic<br />Create<br />Graphics  mySurface;<br />mySurface = this.CreateGraphics();<br />
Basic - Pen<br />(2) To draw lines or outlines of shapes, we need a Pen <br />
Basic - Pen<br />Declare<br />Pen pen1;<br />
Basic - Pen<br />Create<br />2 parameters<br />- Color<br />- thickness<br />Pen pen1;<br />pen1 = new Pen(Color.Blue, 1.0...
Basic - Brush<br />(3) To fill inside shapes, we need a Brush <br />
Basic - Brush<br />Declare<br />Types of brush<br />SolidBrush<br />HatchBrush<br />LinearGradientBrush<br />PathGradientB...
Basic - Brush<br />Create<br />SolidBrush brush1;<br />brush1 = new SolidBrush(Color.Green);<br />
Basic - Brush<br />Types of brush<br />SolidBrush<br />HatchBrush<br />LinearGradientBrush<br />PathGradientBrush<br />Tex...
Draw Lines<br />> New Solution: SpfGraphics<br />> Select Form1.cs, select design view<br />> select events and double cli...
Draw Lines<br />
Draw Lines<br />
Output<br />
Using points & DrawLines<br />Continue in Form1_Paint<br />
Output<br />surface1.DrawLine(pen1, pt1, pt3);<br />surface1.DrawLines(pen1, points);<br />
Draw Rectangle<br />Continue in Form1_Paint<br />
Draw Rectangle<br />
Fill Shape<br />Continue in Form1_Paint<br />
Fill Shape<br />
Draw Polygon<br />Continue in Form1_Paint<br />
Draw Polygon<br />
Draw Text<br />Continue in Form1_Paint<br />
Draw Text<br />
Try it yourself: drawing cross for mousedown<br />VIDEO<br />
Try it yourself!<br />Hint: use the mousedown event<br />Hint: use points (e.X-5, e.Y-5) , (e.X+5, e.Y+5), (e.X+5, e.Y-5) ...
Possible solution<br />
Draw fix line follow mouse<br />
Draw fix line follow mouse<br />New project “lineFollowMouse”<br />
Draw fix line follow mouse<br />// Get the mouse position<br />
Demo:  flexi line follow mouse<br />VIDEO<br />
Flexi line follow mouse<br />// Get the mouse position<br />
Demo: Simple pixel drawing<br />VIDEO<br />
Simple pixel drawing<br />New project: SimplePixelDrawing<br />
Simple pixel drawing<br />
Simple pixel drawing<br />
Simple pixel drawing<br />to continue next page<br />
Simple pixel drawing<br />continue from previous page<br />
Summary<br />Surface, pen and brush<br />Draw Lines<br />Draw Rectangles<br />Draw Polygons<br />Draw Text<br />
Upcoming SlideShare
Loading in...5
×

Graphics

531

Published on

C# Graphics

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
531
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Graphics

  1. 1. C# .NET Graphics <br />Extra – not tested<br />Required for assignment 1<br />
  2. 2. What will we be learning?<br />Surface, pen and brush<br />Draw Lines<br />Draw Rectangles<br />Draw Polygons<br />Draw Text<br />
  3. 3. Basic - Graphics<br />(1) we need to have a Graphics instance (similar to a surface)<br />
  4. 4. Basic<br />Declare<br />Graphics mySurface;<br />
  5. 5. Basic<br />Create<br />Graphics mySurface;<br />mySurface = this.CreateGraphics();<br />
  6. 6. Basic - Pen<br />(2) To draw lines or outlines of shapes, we need a Pen <br />
  7. 7. Basic - Pen<br />Declare<br />Pen pen1;<br />
  8. 8. Basic - Pen<br />Create<br />2 parameters<br />- Color<br />- thickness<br />Pen pen1;<br />pen1 = new Pen(Color.Blue, 1.0f);<br />
  9. 9. Basic - Brush<br />(3) To fill inside shapes, we need a Brush <br />
  10. 10. Basic - Brush<br />Declare<br />Types of brush<br />SolidBrush<br />HatchBrush<br />LinearGradientBrush<br />PathGradientBrush<br />TextureBrush<br />SolidBrush brush1;<br />
  11. 11. Basic - Brush<br />Create<br />SolidBrush brush1;<br />brush1 = new SolidBrush(Color.Green);<br />
  12. 12. Basic - Brush<br />Types of brush<br />SolidBrush<br />HatchBrush<br />LinearGradientBrush<br />PathGradientBrush<br />TextureBrush<br />
  13. 13. Draw Lines<br />> New Solution: SpfGraphics<br />> Select Form1.cs, select design view<br />> select events and double click “Paint” event<br />
  14. 14. Draw Lines<br />
  15. 15. Draw Lines<br />
  16. 16. Output<br />
  17. 17. Using points & DrawLines<br />Continue in Form1_Paint<br />
  18. 18. Output<br />surface1.DrawLine(pen1, pt1, pt3);<br />surface1.DrawLines(pen1, points);<br />
  19. 19. Draw Rectangle<br />Continue in Form1_Paint<br />
  20. 20. Draw Rectangle<br />
  21. 21. Fill Shape<br />Continue in Form1_Paint<br />
  22. 22. Fill Shape<br />
  23. 23. Draw Polygon<br />Continue in Form1_Paint<br />
  24. 24. Draw Polygon<br />
  25. 25. Draw Text<br />Continue in Form1_Paint<br />
  26. 26. Draw Text<br />
  27. 27. Try it yourself: drawing cross for mousedown<br />VIDEO<br />
  28. 28. Try it yourself!<br />Hint: use the mousedown event<br />Hint: 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)<br />
  29. 29. Possible solution<br />
  30. 30. Draw fix line follow mouse<br />
  31. 31. Draw fix line follow mouse<br />New project “lineFollowMouse”<br />
  32. 32. Draw fix line follow mouse<br />// Get the mouse position<br />
  33. 33. Demo: flexi line follow mouse<br />VIDEO<br />
  34. 34. Flexi line follow mouse<br />// Get the mouse position<br />
  35. 35. Demo: Simple pixel drawing<br />VIDEO<br />
  36. 36. Simple pixel drawing<br />New project: SimplePixelDrawing<br />
  37. 37. Simple pixel drawing<br />
  38. 38. Simple pixel drawing<br />
  39. 39. Simple pixel drawing<br />to continue next page<br />
  40. 40. Simple pixel drawing<br />continue from previous page<br />
  41. 41. Summary<br />Surface, pen and brush<br />Draw Lines<br />Draw Rectangles<br />Draw Polygons<br />Draw Text<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×