Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphics Procedure (IDrawable) 1. Basic Procedure For Drawing ThingsToDraw Create Objects From Classes Add Them to PictureBox Use the Paint Event to draw.

Similar presentations


Presentation on theme: "Graphics Procedure (IDrawable) 1. Basic Procedure For Drawing ThingsToDraw Create Objects From Classes Add Them to PictureBox Use the Paint Event to draw."— Presentation transcript:

1 Graphics Procedure (IDrawable) 1

2 Basic Procedure For Drawing ThingsToDraw Create Objects From Classes Add Them to PictureBox Use the Paint Event to draw them on the 2

3 The code 3 This code is from “Assignment3Example.zip”, available on Ctools.

4 Implementing IDrawable Both House and Snowman implement IDrawable. You can see this since both contain all of the properties and methods declared in Idrawable. 4

5 The Classes In addition to implementing everything in IDrawable, your classes should: – Have additional properties to allow the class’s “user” (the programmer of the picture) to customize the features of each object. – Have one or more constructors which allow the customization to occur in one line of code; that is, the constructor should assign values to all of the properties. 5

6 Multiple Constructors Creating multiple constructors in your classes makes them easier to use. I have added a second constructor to the House class (code on next slide). Here’s what you see when you create a new House object: The second constructor uses default values for the colors (DarkRed, White, Red) and the chimney (True). 6

7 Multiple Constructor Code 7

8 How Many Constructors? You can create as many constructors as you want for a class. No two constructors can have exactly the same type of parameter list; for VB to tell them apart, parameter lists will have to vary in type, number, or order. You will see lots of overloaded constructors in the built-in.NET classes. In many cases, you may not know what all of the parameters are for; Microsoft has picked default values of these parameters for you which should work in most cases. However, in cases where you need to set these values to something besides the default, there will be a lengthier constructor which should do the trick. 8

9 Use some cool effects! Chapters 30, 31, and 32 describe many graphics procedures available to you. Within your group’s classes, try to incorporate as many of these procedures as possible. Don’t make every class out of rectangles and ellipses! Explore gradients, textures, pens, paths, text, transformations, etc. Note that we have posted a compilation of forum questions about graphics from last semester in both Resources and forums. Please read through these before posting a new question on Forums. 9

10 The Paint Event There are two ways to get a Graphics object to draw on: 1.Use the CreateGraphics function (g = PictureBox1.CreateGraphics) 2.Use e.Graphics from the Paint event 10


Download ppt "Graphics Procedure (IDrawable) 1. Basic Procedure For Drawing ThingsToDraw Create Objects From Classes Add Them to PictureBox Use the Paint Event to draw."

Similar presentations


Ads by Google