Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 9 Color, Sound and Graphics Key Concepts:  Applying color to GUI  Using images in applications  Using Sounds in applications  Using Graphics.

Similar presentations


Presentation on theme: "Chapter 9 Color, Sound and Graphics Key Concepts:  Applying color to GUI  Using images in applications  Using Sounds in applications  Using Graphics."— Presentation transcript:

1 Chapter 9 Color, Sound and Graphics Key Concepts:  Applying color to GUI  Using images in applications  Using Sounds in applications  Using Graphics class © 2012 EMC Publishing, LLC Slide 1

2 © 2012 EMC Publishing, LLC Slide 2 Chapter 9 Using Color  Color can enhance an application interface.  Control objects have BackColor and ForeColor properties.  Visual Basic color constants can be used to change background and foreground colors at run time.  BackColor and ForeColor can be chnaged at runtime: see synthax in Notes

3 © 2012 EMC Publishing, LLC Slide 3 Chapter 9 The Color Dialog Box Predefined dialog box that allows the user to select a color.

4 © 2012 EMC Publishing, LLC Slide 4 Chapter 9 The ColorDialog Control  Properties include:  Color is the color selected in the dialog box.  AllowFullOpen allows the user to create a custom color.  The Color dialog box is displayed using the ShowDialog() method.

5 © 2012 EMC Publishing, LLC Slide 5 Chapter 9 Using Images  Most objects have a BackgroundImage property.  The Button and Label control objects have an Image property.  Images can be changed at run time using the My.Resources object: Me.btnEvents.Image = My.Resources.Flower Me.BackgroundImage = My.Resources.Balloons

6 © 2012 EMC Publishing, LLC Slide 6 Chapter 9 The SystemSounds Class  Includes five properties for making Windows operating system sounds: Asterisk Beep Exclamation Hand Question  The Play() method is used to make the sound: SystemSounds.Beep.Play()  Applications require the Imports System.Media statement before any declaration

7 © 2012 EMC Publishing, LLC Slide 7 Chapter 9 Playing Sound Files  Visual Basic applications can play Windows WAV audio files.  My.Computer.Audio objects includes the Play() and Stop() methods for working with WAV files.  -Play(resource, playmode)  -Stop()  Audio files must be added to the Resources folder for an application to access them.

8 © 2012 EMC Publishing, LLC Slide 8 Chapter 9 The Timer Control  Applications often perform actions at regular intervals.  The Timer object is used to execute code at regular intervals  Add from the Tollbox to the component tray

9 © 2012 EMC Publishing, LLC Slide 9 Chapter 9 The Timer Control  Properties include:  (Name) should begin with tmr.  Interval is the amount of time that passes before the Tick event procedure executes.  Enabled allows a Tick event to occur at the end of each interval.  Methods include Start() and Stop().

10 © 2012 EMC Publishing, LLC Slide 10 Chapter 9 Animation  Uses a timer control object and a set of images.  Images are cycled in a PictureBox control object to give the impression of motion.  A Case statement can be used to determine which image to display.

11 © 2012 EMC Publishing, LLC Slide 11 Chapter 9 The Graphics Class  Includes numerous methods for creating lines, shapes, solid shapes, and curves and polygons.  Methods require that a drawing surface be defined. Dim formSurface as Graphics=Me.CreateGraphics - This creates a Graphics object from the surface of the form - CreateGraphics method is a control class method that encases a specific’s object area

12 © 2012 EMC Publishing, LLC Slide 12 Chapter 9 The Graphics Class  Methods require that a Pen object be defined. Pen styles can be solid, dashed, and dotted. There are numerous colors to choose from. Dim thinAquaPen As New Pen(Color.Aqua, 2) - the keyword New declares a new object - ColorAqua is a Visual Basic color constant - 2 is the thickness of the line

13 © 2012 EMC Publishing, LLC Slide 13 Chapter 9 The Graphics Class  A drawing surface can be thought as a grid consisting of a set of points with (x, y) values  Each point is a pixel ( picture element ) and the number of pixels in a surface depends on the screen resolution. The point with coordinates (0, 0)is the pixel in the very upper-left corner  Methods can accept coordinates in (x1, y1), (x2, y2) format or as Point structures that define each point.

14 The Graphics Class  The Size property of an object stores both height and width. For many objects ( labels, buttons…)the height and the width correspond to the coordinates of point in the lower right of the object  For a Form object the Size property returns the size of the form Dim formMaxX As Integer = Me.Size.Width ‘300 Dim formMaxX As Integer = Me.Size.Width ‘300 Dim formMaxY as Integer = Me.Size.Height ‘300 Dim formMaxY as Integer = Me.Size.Height ‘300 Returns the Form’s Size property data. © 2012 EMC Publishing, LLC Slide 14

15 © 2012 EMC Publishing, LLC Slide 15 Chapter 9 The Graphics Drawing Surface A form's drawing surface is reduced by the title bar and borders. Each square on the grid represents 10 pixels. Counting the grid marks show that although the form size is 300 by 300, the actual drawing surface is less, about 292 by 265.

16 © 2012 EMC Publishing, LLC Slide 16 Chapter 9 The Graphics Class  The Graphics class methods require a pen along with the shape position and size.  Graphics methods include:  DrawLine(pen,x1,y1,x2,y2)->line from(x1, y1) to (x2, y2)  DrawRectangle(x1,y1,width,height)-> draws rectangle with upper-left corner at (x1,y1) and size width x height  DrawEllipse(x1,y1,width,height)-> draws an ellipse within a rectangular area that has upper-left corner at (x1,y1) and size width x height

17 © 2012 EMC Publishing, LLC Slide 17 Chapter 9 The Graphics Class  DrawArc(pen,x1,y1,width,height,startAngle,sweepAn gle) ->draws an arc tha starts at angle startAngle and continues clockwise sweepAngle degrees. The arc is within a rectangular area that has its upper-left corner at (x1,y1) on a Graphics object with width ang height  Clear(color)-> clears the drawing surface with “color”which can be a System.Drawing color constant or the current object color

18 © 2012 EMC Publishing, LLC Slide 18 Chapter 9 The Graphics Class  The shapes in the TestGraphics application have been drawn using absolute coordinates, meaning that actual sizes were used to specify the shape sizes  Relative coordinates are another option. They are relative to the size of the form. If the form is resized the shapes maintain their relative size and position. See DrawShapes program and change Form’s size.  The Pen class contains the DashStyle property: dashed lines, dotted lines and dash-dot are a few examples.

19 © 2012 EMC Publishing, LLC Slide 19 Chapter 9 Drawing Solid Shapes  The Graphics class methods that fill shapes require a brush along with the shape position and size.: Dim purpleBrush as New SolidBrush(Color.BlueViolet)  FillRectangle(brush,x1,y1,width,height)  FillEllipse(brush,x1,y1,width,height)  FillPie(brush,x1,y1,width,height,startAngle,sweepAngle) The parrameters of the methods are the same as corresponding Draw methods.

20 © 2012 EMC Publishing, LLC Slide 20 Chapter 9 The Point Structure A point has an x-coordinate a y-coordinate A Point structure can be defined with X and Y members: Dim minPoint As Point minPoint.X=0 minPoint.Y=0 Or Dim minPoint as New Point(0, 0)

21 © 2012 EMC Publishing, LLC Slide 21 Chapter 9 Drawing curves and Polygons DrawCurve(pen, points) DrawClosedCurve(pen, points) FillClosedCurve(brush, points) DrawPolygon(pen, points) FillPolygon(brush, points)

22 © 2012 EMC Publishing, LLC Slide 22 Chapter 9 The MouseDown Event  Occurs when the user clicks the form or object associated with the MouseDown event.  Select Code window, click the object name in the Class Name list and then select MouseDown in the Method Name list  The e parameter includes X and Y properties specific to the mouse click that raised the event. The X and Y properties can be used to determine the coordinates of the mouse click.


Download ppt "Chapter 9 Color, Sound and Graphics Key Concepts:  Applying color to GUI  Using images in applications  Using Sounds in applications  Using Graphics."

Similar presentations


Ads by Google