Computer Programming I

Slides:



Advertisements
Similar presentations
Chapter 9 Color, Sound and Graphics
Advertisements

COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
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.
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.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
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)
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.
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.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 2 Creating Applications With Visual Basic.NET.
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.
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.
The PictureBox Control Prefix Prefix – pic Image Property PictureBox Image Property – Changes the image or file that appears inside of the PictureBox SizeMode.
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
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
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.
COMPUTER PROGRAMMING I SUMMER 2011 Objective 8.01 Understand coordinate systems. (3%)
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.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6A Methods (Concepts)
COM148X1 Interactive Programming Lecture 8. Topics Today Review.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Use TryParse to Validate User Input
Visual Basic Fundamental Concepts
Chapter 1: An Introduction to Visual Basic .NET
A variable is a name for a value stored in memory.
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Working in the Forms Developer Environment
Flash Interface, Commands and Functions
Apply Procedures to Develop Message, Input, and Dialog Boxes
Chapter 2 – Introduction to the Visual Studio .NET IDE
Chapter 9 – Additional Controls and Objects
3.01 Apply Controls Associated With Visual Studio Form
Use TryParse to Validate User Input
Objective 8.02 Apply Procedures to Create Picture Boxes using Images.
3.01 Apply Controls Associated With Visual Studio Form
Graphics and Multimedia
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Visual Basic..
CASE Tools Graphical User Interface Programming Using C#
Chapter 9 – Additional Controls and Objects
Additional Topics in VB.NET
Repetition and Multiple Forms
Topics Graphical User Interfaces Using the tkinter Module
Chapter 12 Graphics in Windows and the Web
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
GUI Programming in Visual Studio .NET
CPT 450 Computer Graphics 3rd Lecture.
Presentation transcript:

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

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 Timer Properties Timer1 in the Component Tray

Timer Control (Name) The name of a timer should start with tmr Enabled Timer Properties Description (Name) The name of a timer should start with tmr Enabled True if the timer can respond to user interaction, otherwise false (default) Interval The interval sets the time in milliseconds between elapsed events. 1000 = 1 second Timer Event Description Start Starts by raising the Elapsed event by setting Enabled to True Stop Stops 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 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 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

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: http://msdn.microsoft.com/en-us/library/5b4t5f7s.aspx For more information on graphics http://msdn.microsoft.com/en-us/library/ac148eb3.aspx