COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Apply Procedures to Develop Menus,
Advertisements

Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
Chapter 9 Color, Sound and Graphics
Chapter 1: An Introduction to Visual Basic 2012
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Graphics and Multimedia Session 13 Mata kuliah: M0874 – Programming II Tahun: 2010.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
Chapter 1: An Introduction to Visual Basic.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Chapter 13 Graphics, Animation, Sound, and Drag-and-Drop Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Mouse draw Using the mouse and a palette to make a picture.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Mouse event handling Mouse events( delegates EventHandler, event arguments EventArgs) MouseEnter: raised if the mouse cursor enters the area of the control.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
Chapter 9 - VB 2008 by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control 9.2 Seven Elementary.
1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes and Combo Boxes 9.2 Eight Additional Controls and Objects 9.3 Multiple-Form Objects 9.4 Graphics.
Visual C++ Programming: Concepts and Projects Chapter 6A: Methods (Concepts)
CST238 Week 5 Questions / Concerns? Announcements – HW#1 due (Project ideas) – Check-off Take Home lab#4 Recap New topics – Drawing Coming up: – GUI Bloopers.
Multimedia ! Graphics ! Animation ! Sound Tip Of the Day 4 Tip of the Day: When using graphic methods at Form Load, the AutoRedraw property of the container.
1 Windows Graphics. 2 Objectives You will be able to Use the Windows GDI+ to draw arbitrary figures and text on a Windows form. Add a handler for the.
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
1-1 OBJ Copyright 2003, Paradigm Publishing Inc. Dr. Joseph Otto Silvia Castaneda Christopher deCastro CSULA Macromedia Flash MX Introduction.
Graphics and Multimedia Part #2
BIM211 – Visual Programming Objects, Collections, and Events 1.
COM148X1 Interactive Programming Lecture 6. Topics Today Generate Random Numbers Graphics Animation.
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes and Combo Boxes 9.2 Eight Additional Controls and Objects 9.3 Multiple-Form Programs 9.4 Graphics.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
VB.NET Additional Topics
Some graphics. Projects included A slideshow a dark moon moving phases of the moon billiards Your own icons and bitmaps Pie chart.
Events with Data Arguments Data Values Travel with e.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Tutorial 6 The Repetition Structure
BIM211 – Visual Programming Interacting with Users Graphics 1.
McGraw-Hill © 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 13 Graphics, Animation, Sound and Drag-and-Drop.
COMPUTER PROGRAMMING I SUMMER 2011 Objective 8.02 Apply Procedures to Create Picture Boxes using Images. (5%)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
16.9 Introduction to Multimedia Visual Basic offers many convenient ways to include images and animations in programs Computing field decades ago mainly.
Events with Data Arguments Data Values Travel with e.
Images Part 11 dbg. 2 Images The form and several controls can display a number of different types of image files in the BackgroundImage Property. These.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6A Methods (Concepts)
COM148X1 Interactive Programming Lecture 8. Topics Today Review.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Chapter 1: An Introduction to Visual Basic .NET
Flash Interface, Commands and Functions
Chapter 9 – Additional Controls and Objects
3.01 Apply Controls Associated With Visual Studio Form
Objective 8.02 Apply Procedures to Create Picture Boxes using Images.
3.01 Apply Controls Associated With Visual Studio Form
Computer Programming I
Graphics and Multimedia
Microsoft® Small Basic
Drawing Mouse and Keyboard Events Part A - Drawing
CASE Tools Graphical User Interface Programming Using C#
Repetition and Multiple Forms
Topics Graphical User Interfaces Using the tkinter Module
Chapter 12 Graphics in Windows and the Web
CPT 450 Computer Graphics 3rd Lecture.
Presentation transcript:

COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)

Objective/Essential Standard Essential Standard 8.00 Apply procedures to develop graphics applications Indicator 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)

The Timer Control You can add a Timer control to your module and use it to “animate” your picture. A timer generates recurring events.  Code inside the timer event will recur until the timer is stopped. The Timer is located in the Components area of your Toolbox. Click on it, then click on your form. The Timer will display in your Component Tray.

Using the Timer Control Timer1 in the Component Tray Timer Properties

Timer Control Timer PropertiesDescription (Name)The name of a timer should start with tmr EnabledTrue if the timer can respond to user interaction, otherwise false (default) IntervalThe interval sets the time in milliseconds between elapsed events = 1 second Timer EventDescription StartStarts by raising the Elapsed event by setting Enabled to True StopStops by raising the Elapsed event by setting Enabled to False

Using the Timer Control To set the timer interval at runtime. tmrName.Interval = number in milliseconds  Example: tmr2Secs.Interval = 2000 To enable/disable the timer at runtime. tmrName.Enabled = True/False  Example tmr2Secs.Enabled = True

Using the Timer Control To create an event for the timer, create a Tick event.  Double Click on the Timer control  Type the code The code that is to repeat goes in the timer tick event. To start the timer timer1.Start() To stop the timer timer1.Stop()

PictureBox & Timer Example Private Sub tmrChange_Tick(ByVal sender As Object, ByVal e As _ System.EventArgs) Handles tmrChangeTick Const MAX_IMAGES As Integer = 3 Static ImageNum as Integer = 0‘use Static to hold the value. Select Case ImageNum Case 0 Me.picImage.Image = My.Resources.fish Case 1 Me.picImage.Image = My.Resources.star Case 2 Me.picImage.Image = My.Resources.moon ImageNum = (ImageNum + 1) Mod intMAXIMAGES 'determine next image number End Sub

The Graphics Class The Graphics class can be used to draw shapes. This class contains methods for creating circles, lines, rectangles and other shapes on a drawing surface.  The drawing surface can be the surface of a form, a button or almost any other control object. The drawing surface is define by assigning an object’s surface to a Graphics object.

The CreateGraphics Control CreateGraphics control  A control class method  Encases a specific object surface area  Available with most control objects

The CreateGraphics Control The drawing surface can be the surface of a form, a button or almost any other object. Syntax  Dim SurfaceName As Graphic = controlObject.CreateCraphics Examples to declare the drawing surface  Using the Form itself as a surface Dim FormSurface As Graphic = Me.CreateGraphics  Using a Button as a surface Dim ButtonSurface As Graphic = btnOn.CreateGraphics

Drawing on the Graphics Surface Defining a Drawing Pen  Drawing on a surface requires a Pen object  The pen, pen color and line thickness are declared in the same statement. Creating a Drawing Pen  The keyword New declares a new object.  Syntax Dim PenName As New Pen(Color.whatever, size) Size must be an integer  Example: Dim ThinAquaPen As New Pen(Color.Aqua, 2) Why create a pen?  You can use this penin multiple places, then if you want to change the color, you only have to change it in the declaration

Drawing on the Graphics Surface After defining a surface and a pen, Graphics class methods are used to draw on the surface. Drawing Surface  A grid consisting of a set of points with x values and y values.  Each point is a pixel.  0,0 is the upper-left corner.  Size Property of an object stores both a height an width and can be used to determine the point in the lower-right-hand of an object.

Graphics Methods Require a pen along with the shape position and size. DrawLine(pen, x1, y1, x2, y2)  Draws a line that extends from x1, y1 to x2, y2  Example surface.DrawLine(MyRedPen, 20, 50, 150, 50)

Graphics Methods DrawRectangle(pen, x1, y1, width, height)  Draws a rectangle with the upper-left corner at coordinates x1, y1 on a graphics object and is width wide and height high  Example surface.DrawRectangle(MyRedPen, 50, 50, 100, 50)

Drawing on the Graphics Surface DrawEllipse(pen, x1,y1,width, height)  Draws an ellipse within a rectangular area that has its upper-left corner at coordinates x1, y1 on a graphics object and is width wide and height high  Example surface.DrawEllipse (MyRedPen, 50, 50, 50, 50)

Drawing on the Graphics Surface DrawArc(pen, x1,y1,width, height, startAngle, sweepAngle)  Draws an arc that starts at angle startAngle and continues clockwise sweepAngle degrees.  The arc is within a rectangular are that has its upper-left corner at coordinates x1, y1 on a graphics object and is width wide and height high  Example surface.DrawArc(MyRedPen, 50, 50, 50, 50, 0, 180)

Drawing on the Graphics Surface Clear(color)  Clears the drawing surface with color Example surface.Clear(me.Backcolor)  ‘Wipes the surface with the color of the form

The Pen The Pen class contains the DashStyle property for defining pen style. DashStyle Options  Solid, Dash, Dot, DashDot, DashDotDot, Custom Example of Declaring a Pen Object myPen.DashStyle = Drawing2D.DashStyle.DashDotDot

Drawing Solid Shapes The Graphics class also includes methods for creating solid (filled) shapes Example of Declaring a SolidBrush Object Dim PurpleBrush As New SolidBrush(Color.BlueViolet) Why create a brush?  You can use this brush in multiple places, then if you want to change the color, you only have to change it in the declaration.

Drawing Solid Shapes The Graphics class methods that fill shapes require a brush along with the shape position and size. FillRectangle(brush, x1, y1, width, height)  Surface.FillRectangle(blackBrush, 0, 0, 200, 200) FillEllipse (brush, x1, y1, width, height)  Surface.FillEllipse(GreenBrush, 0, 0, 200, 200) FillPie(brush, x1, y1, width, height, startAngle, sweepAngle)  Surface.FillPie(violetBrush, 0, 210, 50, 50, 0, 180) 'half circle

The Point Structure A point has an x-coordinate and a y-coordinate that together indicates a specific location Example of declaring a point: Dim MinPoint as Point MinPoint.X = 0 MinPoint.Y = 0

The Point Structure You can declare a point with the X and Y values included when the keyword New is used Example: Dim MinPoint As New Point(0,0) You can overload a Graphics method to accept Point variables in place of coordinates.

The Point Structure Using the size property of an object, you can set a maximum point that can be updated if the object is resized. Example of declaring a point: Dim MaxPoint as New Point (Me.btnDrawHere.Size.Width, Me.btnDrawHere.Size.Height)

Using the Graphics Class for Polygons & Curves The Graphics class also includes methods for creating polygons and curves on a drawing surface. The number of points that define a curve or polygon vary depending upon the specific shape. A set of points in an array is required by these methods. Creating a Points array Dim CurvePoints() As Point = {New Point(10, 30), New Point(35, 35), New Point(75, 80), New Point(120, 20)}

Polygons & Curves Using a Points Array DrawCurve(pen, points)  Creates a curve on a Graphics object using the points in the points array  Each point will represent where the line drawn will curve. DrawClosedCurve(pen, points)  Creates a closed curve on a Graphics object using the points in the points array  Each point will represent where the line drawn will curve.  The curve is automatically continued from the last point to the first point to close the curve.

Polygons & Curves Using a Points Array FillClosedCurve(brush, points)  Creates a filled, closed curve on a Graphics object using the points in the points array.  Each point will represent where the line drawn will curve.  The curve is automatically continued from the last point to the first point to close the curve. DrawPolygon(pen, points)  Creates a closed polygon on a Graphics object using the points in the points array.  Each point will represent where the line drawn will change.  A line is automatically created form the last point to the first to close the polygon

Polygons & Curves Using a Points Array FillPolygon(brush, points)  Creates a filled, closed polygon on a Graphics object using the points in the points array.  Each point will represent where the line drawn will change.  A line is automatically created form the last point to the first to close the polygon

Drawing Shapes Examples Create a program that will draw an example of each of the Draw and Fill methods learned.

Drawing Shapes Examples

Sample output. Note that the graphics are drawing over each other.

Curves & Polygons Examples Create a program that will draw an example of each of the Draw and Fill methods learned that use the Points array.

Curves & Polygons Examples

Conclusion This PowerPoint provided an overview of the Graphics Class in Visual Studio. For more information on timers:  For more information on graphics 