Anda di halaman 1dari 42

Animation/Grap

hics
Using
VB .Net
Contents

• Objective

• Introduction
• Graphics
• Animation
• Net Frame Work
• VB .Net
• Introduction
• How to create graphics in VB .net?
• Classes
• Methods
• Program
• How Animation is generated?
• Timer control
• Programs
• Advantages of VB .Net animation
feature.

• Future scope of animation using


VB .net

• References
• Objective:
VB.Net is a unique language based on Microsoft .Net
Framework. VB.Net has a healing power for Visual Basic
deficiencies and robustness to build advance application
including quality websites. It is gaining popularity due to its
excellent abilities. The number of inbuilt classes in .Net Base
Class Library is so vast that it makes many tough and time
consuming jobs in simple few code steps. Hence there is no
need to write additional code for common routine programs and
behaviours.

Developers are happy that VB.Net is now equipped with


implementation inheritance. They can inherit any base class
created in VB.Net or other .Net compliant language like C#.
With the help of visual inheritance, every control and its
attributes can be inherited and reused to build customized
control. Inheritance has explored all the corners of code
reusability in VB.Net. It is now pure object oriented language.
The error handling skills have been sharpened and highly
structured. We can handle inbuilt error objects and even raise
our own customized error events in VB.Net. It fulfils the
objective of flexible error handling, smart debugging and
mitigating defects at runtime.

Quality web development is now possible in VB.Net. Any type of


website or web-service can be developed with beautiful design
architectures and diverse complexity. Through web-services,
we can access any web server resource including data objects,
any custom file or SharePoint page etc. Normally data returned
by web-service methods is in the form of Datasets. Client
applications which access the web-service, receive the data in
XML format. Nowadays XML, being standard data
representation, is commonly used by .Net compliant languages
to exchange their data through various network protocols
including Simple Object Access Protocol (SOAP). As XML is very
light, the data communication is fast and can be processed in
secured manner.
With so many special features, VB.Net now comes with
powerful Microsoft Visual Studio Integrated Development
Environment (IDE) and Rapid Application Development utilities.
MSIL code and JIT compilation in VB.Net turns out to easy
deployment and maintenance. Client machine just needs .Net
Framework as pre-requisite and rest of the process is taken
care by CLR during runtime. Thus VB.Net solution needs
minimum time and cost for deployment process. Diverse
applications based on Windows, Web, and Mobile
Communication can be developed with less time and effort.
Here, we are going to analyze the implementation of
Animations and Graphics using VB.Net. With increasing
importance of User-friendly Interfaces more interactive and
expressive pages have become an utmost necessity. VB.Net
features all these important aspects in the form of security,
quality and user-friendly interface.
• Graphics:
• Graphics (from Greek γραφικός graphia) are visual
presentations on some surface, such as a wall, canvas,
computer screen, paper, or stone to brand, inform,
illustrate, or entertain.

• Graphics often combine text, illustration, and colour

• Examples are photographs, drawings, Line Art, graphs,


diagrams, typography, numbers, symbols, geometric
designs, maps, engineering drawings, or other images.

• Uses:

• Graphics are visual elements often used to point readers


and viewers to particular information.

• They are also used to supplement text in an effort to aid


readers in their understanding of a particular concept or
make the concept more clear or interesting.

• Business: Graphics are commonly used in business and


economics to create financial charts and tables. The term
Business Graphics came into use in the late 1970s, when
personal computers became capable of drawing graphs
and charts instead of using a tabular format. Business
Graphics can be used to highlight changes over a period of
time.

• Advertising: It is one of the most profitable uses of


graphics; artists often do advertising work or take
advertising potential into account when creating art, to
increase the chances of selling the artwork.

• Education :Graphics are heavily used in textbooks,


especially those concerning subjects such as geography,
science, and mathematics, in order to illustrate theories
and concepts, such as the human anatomy. Diagrams are
also used to label photographs and pictures.
• Educational animation is an important emerging field of
graphics. Animated graphics have obvious advantages
over static graphics when explaining subject matter that
changes over time.

• The Oxford Illustrated Dictionary uses graphics and


technical illustrations to make reading material more
interesting and easier to understand. In an encyclopedia,
graphics are used to illustrate concepts and show
examples of the particular topic being discussed.

• In order for a graphic to function effectively as an


educational aid, the learner must be able to interpret it
successfully. This interpretative capacity is one aspect of
graphicacy.

• Film and animation Computer graphics are often used in


the majority of new feature films, especially those with a
large budget. Films that heavily use computer graphics
include The Lord of the Rings film trilogy, the Harry Potter
films, Spider-Man and War of the Worlds.

Photograph Drawing Drawing

• Animation:
• Animation is the rapid display of a sequence of images of
2-D or 3-D artwork or model positions in order to create an
illusion of movement.

• Animation is an optical illusion of motion due to the


phenomenon of persistence of vision, and can be created
and demonstrated in a number of ways.

• The most common method of presenting animation is as


a motion picture or video program, although several other
forms of presenting animation also exist.

• Object animation refers to the use of regular inanimate


objects in stop- motion animation, as opposed to specially
created items.

• Graphic animation uses non-drawn flat visual graphic


material (photographs, newspaper clippings, magazines,
etc.) which are sometimes manipulated frame-by-frame to
create movement. At other times, the graphics remain
stationary, while the stop-motion camera is moved to
create on-screen action.

• .Net Frame Work


VB C# J# Other Lang.

Compiler Compiler Compiler Compiler

Microsoft Common Infrastructure

Microsoft Intermediator Language/


Common Intermediate Language

Common Language Runtime

10101010

MSIL/IL/CIL:

• IL stands for Intermediate Language.

• MSIL stands for Microsoft Intermediate Language.


• CIL stands for Common Intermediate Language.

• All .Net source Code is compiled with the help of


intermediate language.

• IL is then converted to machine code.

CLR

• CLR stands for Common Language Runtime and


it forms the heart of the .Net framework.

• All language have runtime to take care of the code


execution of the program.

• For eg. In Visual Basic 6.0 has MSVBVM60.dll


(Microsoft Visual Basic Virtual Machine) in visual
basic .net has CLR in java we use JVM (Java Virtual
Machine).

CTS

• CTS stands for Common Type System. In order


that two languages communicate smoothly CLR
has CTS.

• Two different languages communicate Microsoft


introduced Common type system.
• For eg. Integer in visual basic 6.0 and int data
type in c language will be converted into
system.int32 which is data type of CTS.

CLS

• CLS stands for Common Language


Specification.

• This is the subset of CTS, which all .Net language


are expected to support.

• It was always a dream of Microsoft to write all


different languages into one umbrella and CLS is
one step towards that Microsoft has defined CLS,
which are nothing but guidelines, that language
should follow so that it can communicate with
others.

• Feature

1. .Net Support Multilanguage:


VB C# C++ ASP
(.vb) (.cs) (.cpp) (.aspx)

Development
FCL
tool

Application.exe

2. .Net support cross platform:

Application.exe

WindowsXP Linux Macintosh SunSolaris

3. Based on CLR, FCL, JIT Technology:


Application.ex
e

JIT Compiler

Object
Code

CLR

FCL

OS and Hardware

•VB .Net
• VB .Net is a fully object orient programming
Language (VB7.0, VB7.1, VB8.0, VB9.0, VB10.0 or
VBx) all these are versions of VB .Net.

• VB .Net is a platform independent language.


Platform independent means it can run in any
Operating system.

• VB .Net is platform independent because of two


reasons:
1. It can run on any platform or operating system.
2. CLR (Common Language Runtime) can be
manufactured by any vendor or any company.

• VB .Net use common runtime environment which


means it compile as well as run the program but use
more then one language syntax.

• In VB .Net can create three types of applications:


1. Console application
2. Window application
3. Web application

• How to create graphics in VB


.net???

• Some classes used to create graphics:


 To create graphics in VB .Net, we use the
class Graphics.
 To fill the rectangle with any colour, we use
the class Brushes or SolidBrush Class.
 To draw only outline of rectangle/ellipse with
any colour, we use the class Pens.
• Some important methods of this class are:-
 DrawRectangle()

 DrawEllipse()
 DrawString()
 DrawLine()
 DrawIcon()
 DrawImage()
 FillRectangle()
 FillEllipse()

• General Syntax to implement


Methods mention above:

1. To Draw Rectangle Method:


DrawRectangle(colour name using pens class,
x coordinate, y coordinate, length, width)

2. To Draw Ellipse Method :

DrawEllipse (colour name using pens class, x


coordinate, y coordinate, length, width)
3. To Draw String Method:

DrawString (string, set the font, colour name, x


coordinate, y coordinate)

4. To Draw Line Method:

DrawLine(colour name, x1, y1, x2, y2 )

5. To Fill Rectangle Method:

FillRectangle(colour name using brush class, x


coordinate, y coordinate, length, width)

6. To Fill Ellipse Method:

FillEllipse (colour name using brush class, x


coordinate, y coordinate, length, width)

7. To Draw Icon Method:

DrawIcon (Path of icon class, x coordinate, y


coordinate)

8. To Draw Image Method:

DrawImage (Path of image using image class, x


coordinate, y coordinate)
•Examples:

1. Program demonstrating methods for generating


graphics.
Coding:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim a As Graphics
a = Me.CreateGraphics
Dim x As New Font("Arial", 15, FontStyle.Italic)
a.FillEllipse(Brushes.Wheat, 60, 60, 30, 50)
a.FillEllipse(Brushes.Black, 70, 80, 3, 3)
a.FillEllipse(Brushes.Black, 80, 80, 3, 3)
a.DrawLine(Pens.Black, 78, 88, 90, 88)
a.DrawLine(Pens.Chocolate, 75, 110, 75, 200)
a.DrawLine(Pens.Chocolate, 75, 120, 60, 170)
a.DrawLine(Pens.Chocolate, 75, 120, 100, 120)
a.DrawLine(Pens.Chocolate, 100, 120, 140, 100)
a.DrawLine(Pens.Chocolate, 75, 200, 60, 240)
a.DrawLine(Pens.Chocolate, 75, 200, 90, 240)
a.FillEllipse(Brushes.BlanchedAlmond, 140, 10, 220, 140)
a.FillRectangle(Brushes.Crimson, 170, 40, 160, 80)
a.DrawString("Graphic Era University",x,Brushes.Black,150,70)
End Sub
End Class
Output:

2. Program demonstrating methods for generating


graphics.
Coding:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click

Dim a As Graphics
Dim c1 As Image = Image.FromFile("E:\gcar1.jpg")
Dim s As Image = Image.FromFile("E:\sun.jpg")
Dim g As Image = Image.FromFile("E:\graphic2.png")
Dim h1 As Image = Image.FromFile("E:\house1.gif")
Dim h2 As Image = Image.FromFile("E:\house2.gif")
Dim c2 As Image = Image.FromFile("E:\car2.gif")
Dim f As New Font("Arial", 20, FontStyle.Italic)

a = Me.CreateGraphics

a.FillRectangle(Brushes.Brown, 90, 140, 100, 105)


a.FillRectangle(Brushes.Black, 100, 150, 30, 70)
a.FillRectangle(Brushes.Black, 150, 150, 30, 70)
a.FillRectangle(Brushes.Black, 130, 230, 20, 15)
a.FillRectangle(Brushes.Brown, 45, 170, 10, 60)
a.FillEllipse(Brushes.Green, 20, 70, 60, 100)
a.DrawImage(c1, 0, 230)
a.DrawImage(s, 300, 0)
a.DrawImage(g, 190, 140)
a.DrawImage(h1, 463, 140)
a.DrawImage(c2, 342, 155)
a.DrawString("Graphic Era University", f, Brushes.Cornsilk, 85, 95)
a.FillRectangle(Brushes.Gray, 90, 245, 373, 50)
a.FillRectangle(Brushes.Gray, 0, 260, 100, 35)
a.FillRectangle(Brushes.Green, 0, 295, 463, 50)
a.FillRectangle(Brushes.Gray, 90, 245, 373, 50)
a.DrawImage(h2, 463, 224)
End Sub
End Class

Output:
How to generate animation?

Before knowing How to create or generate Animation


we should know What is animation? Animation is
the rapid display of a sequence of images of 2d or 3d
artwork or what all graphics we have learned creating
in order to create an illusion of motion due to the
phenomenon of persistence of vision and can be
created and demonstrated in number of ways to
achieve this illustration in VB .Net we use timer
control.
This control has two important properties:
1. Enable
2. Interval

 There are two important values of enable property


TRUE and FALSE.

 By default the value of this property is equal to


false.

 Timer control works only when the user set the


value of this property is equal to TURE.

 Interval decide the execution time of coding.

 By default the value of this property is equal to


100.

1000 means approx 1sec.


2000 means approx 2sec.

 The important event of timer control is:

TICK()

Program to create a screen saver using VB .Net?


Coding:
Module SubMain
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_NOZORDER = &H4
Public Const SWP_SHOWWINDOW = &H40
Public Const GWL_STYLE = -16
Public Const WS_CHILD = &H40000000
Public Const GWL_HWNDPARENT = -8
Public Const HWND_TOP = 0

Public Structure RECT


Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure

Public Declare Function GetClientRect Lib "user32" ( _


ByVal hwnd As Integer, _
ByRef lpRect As RECT) As Integer

Public Declare Function GetWindowLong Lib "user32" Alias


"GetWindowLongA" ( _
ByVal hwnd As Integer, _
ByVal nIndex As Integer) As Integer

Public Declare Function SetWindowLong Lib "user32" Alias


"SetWindowLongA" ( _
ByVal hwnd As Integer, _
ByVal nIndex As Integer, _
ByVal dwNewInteger As Integer) As Integer

Public Declare Function SetWindowPos Lib "user32" ( _


ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal cx As Integer, _
ByVal cy As Integer, _
ByVal wFlags As Integer) As Integer

Public Declare Function SetParent Lib "user32" ( _


ByVal hWndChild As Integer, _
ByVal hWndNewParent As Integer) As Integer

Public Enum ActionType


actConfigure
actPreview
actRun
End Enum

Public m_Action As ActionType

Public Sub Main(ByVal args As String())


' See what we should do.
If args.Length = 0 Then
m_Action = ActionType.actRun
Else
Select Case args(0).ToLower().Substring(0, 2)
Case "/p"
m_Action = ActionType.actPreview
Case "/c"
m_Action = ActionType.actConfigure
Case "/s"
m_Action = ActionType.actRun
Case Else
m_Action = ActionType.actRun
End Select
End If

' Do it.
Select Case m_Action
Case ActionType.actRun
' Normal screen saver.
Dim canvas As New frmCanvas
Application.Run(canvas)
Case ActionType.actConfigure
' Configure.
Dim dlg_config As New frmConfig
Application.Run(dlg_config)
Case ActionType.actPreview
' Preview.
Dim canvas As New frmCanvas
SetForm(canvas, args(1))
Application.Run(canvas)
End Select
End Sub

' Reparent the form into the preview window.


Private Sub SetForm(ByRef frm As Form, ByRef arg As String)
Dim style As Integer
Dim preview_hwnd As Integer = Integer.Parse(CType(arg, String))
Dim r As New RECT

' Get the preview window's size.


GetClientRect(preview_hwnd, r)

With frm
.WindowState = FormWindowState.Normal
.FormBorderStyle = FormBorderStyle.None
.Width = r.right
.Height = r.bottom
End With

' Add the WS_CHILD style to the form.


style = GetWindowLong(frm.Handle.ToInt32, GWL_STYLE)
style = style Or WS_CHILD
SetWindowLong(frm.Handle.ToInt32, GWL_STYLE, style)

' Reparent the form into the preview window.


SetParent(frm.Handle.ToInt32, preview_hwnd)

' Set the form's GWL_PARENT value to the preview window.


SetWindowLong(frm.Handle.ToInt32, GWL_HWNDPARENT, preview_hwnd)

' Position the form in the preview window.


SetWindowPos(frm.Handle.ToInt32, 0, r.left, 0, r.right, r.bottom, _
SWP_NOACTIVATE Or SWP_NOZORDER Or SWP_SHOWWINDOW)
End Sub
End Module
Output:
Program demonstrating how to net rotating gradient.
Coding:
Imports System.Drawing.Drawing2D

Public Class Form1


Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()


MyBase.New()

'This call is required by the Windows Form Designer.


InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.


Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer


Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer


'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents picCanvas As System.Windows.Forms.PictureBox
Friend WithEvents tmrRotate As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.picCanvas = New System.Windows.Forms.PictureBox
Me.tmrRotate = New System.Windows.Forms.Timer(Me.components)
CType(Me.picCanvas,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'picCanvas
'
Me.picCanvas.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.picCanvas.Location = New System.Drawing.Point(8, 8)
Me.picCanvas.Name = "picCanvas"
Me.picCanvas.Size = New System.Drawing.Size(272, 269)
Me.picCanvas.TabIndex = 0
Me.picCanvas.TabStop = False
'
'tmrRotate
'
Me.tmrRotate.Enabled = True
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(19, 46)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.picCanvas)
Me.Font = New System.Drawing.Font("Times New Roman", 30.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0,
Byte))
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.picCanvas,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region

Private m_Theta As Single = 0


Private m_Delta As Single = 10

Private Sub picCanvas_Paint(ByVal sender As Object, ByVal e As


System.Windows.Forms.PaintEventArgs) Handles picCanvas.Paint
Dim rect As New Rectangle(-3, -3, picCanvas.ClientSize.Width + 6,
picCanvas.ClientSize.Height + 6)
Dim br As New LinearGradientBrush(rect, Color.Red, Color.Blue,
m_Theta)
e.Graphics.Clear(picCanvas.BackColor)
e.Graphics.FillRectangle(br, Me.ClientRectangle)
br.Dispose()
m_Theta += m_Delta

Dim string_format As New StringFormat


string_format.Alignment = StringAlignment.Center
string_format.LineAlignment = StringAlignment.Center
e.Graphics.DrawString("Graphic Era", Me.Font, Brushes.Black, _
picCanvas.ClientSize.Width \ 2, _
picCanvas.ClientSize.Height \ 2, _
string_format)
End Sub

Private Sub tmrRotate_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles tmrRotate.Tick
picCanvas.Invalidate()
End Sub

End Class

Output:
Program using VB .Net creating stick figures performing
action.
Coding:
Code for animate button
Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
Private Istep As Integer
Private MyImage As Bitmap
Private MyGraphic As Graphics
Private Mypen As Pen
Private DelPen As Pen

Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal


eventArgs As System.EventArgs) Handles Command1.Click
Istep = 1
Timer1.Interval = 40
Timer1.Enabled = True
End Sub

Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal


eventArgs As System.EventArgs) Handles Command2.Click
Me.Close()
End Sub

Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal


eventArgs As System.EventArgs) Handles MyBase.Load
Timer1 = New Windows.Forms.Timer
MyImage = New Bitmap(M.Width, M.Height)
MyGraphic = Graphics.FromImage(MyImage)
Mypen = New Pen(Color.Black, 1)
DelPen = New Pen(Color.White, 1)

MyGraphic.DrawLine(Mypen, 300, 120, 300, 170)


MyGraphic.DrawLine(Mypen, 280, 130, 320, 130)
MyGraphic.DrawLine(Mypen, 300, 170, 280, 190)
MyGraphic.DrawLine(Mypen, 300, 170, 320, 190)
MyGraphic.DrawEllipse(Mypen, 285, 90, 30, 30)
MyGraphic.DrawLine(Mypen, 100, 120, 100, 170)
MyGraphic.DrawLine(Mypen, 80, 130, 120, 130)
MyGraphic.DrawLine(Mypen, 100, 170, 80, 190)
MyGraphic.DrawLine(Mypen, 100, 170, 120, 190)
MyGraphic.DrawEllipse(Mypen, 85, 90, 30, 30)
MyGraphic.DrawLine(Mypen, 120, 130, 200, 190)

M.Image = MyImage
End Sub

Private Sub M_Click(ByVal eventSender As System.Object, ByVal eventArgs


As System.EventArgs) Handles M.Click
Istep = 1
Timer1.Interval = 100
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal


eventArgs As System.EventArgs) Handles Timer1.Tick
MyGraphic = Graphics.FromImage(MyImage)
Select Case Istep
Case 1
MyGraphic.DrawLine(DelPen, 120, 130, 200, 190)
MyGraphic.DrawLine(Mypen, 120, 130, 180, 190)
Case 2
MyGraphic.DrawLine(DelPen, 100, 130, 120, 130)
MyGraphic.DrawLine(DelPen, 120, 130, 180, 190)
MyGraphic.DrawLine(Mypen, 100, 130, 118, 120)
MyGraphic.DrawLine(Mypen, 118, 120, 175, 190)
Case 3
MyGraphic.DrawLine(DelPen, 100, 130, 118, 120)
MyGraphic.DrawLine(DelPen, 118, 120, 175, 190)
MyGraphic.DrawLine(Mypen, 100, 130, 115, 110)
MyGraphic.DrawLine(Mypen, 115, 110, 165, 190)
Case 4
MyGraphic.DrawLine(DelPen, 100, 130, 115, 110)
MyGraphic.DrawLine(DelPen, 115, 110, 165, 190)
MyGraphic.DrawLine(Mypen, 100, 130, 105, 110)
MyGraphic.DrawLine(Mypen, 105, 110, 155, 180)
Case 5
MyGraphic.DrawLine(DelPen, 100, 130, 105, 110)
MyGraphic.DrawLine(DelPen, 105, 110, 155, 180)
MyGraphic.DrawLine(Mypen, 100, 130, 95, 110)
MyGraphic.DrawLine(Mypen, 95, 110, 145, 170)
Case 6
MyGraphic.DrawLine(DelPen, 100, 130, 95, 110)
MyGraphic.DrawLine(DelPen, 95, 110, 145, 170)
MyGraphic.DrawLine(Mypen, 100, 130, 85, 110)
MyGraphic.DrawLine(Mypen, 85, 110, 135, 160)
Case 7
MyGraphic.DrawLine(DelPen, 85, 110, 135, 160)
MyGraphic.DrawLine(Mypen, 85, 110, 125, 140)
Case 8
MyGraphic.DrawLine(DelPen, 85, 110, 125, 140)
MyGraphic.DrawLine(Mypen, 85, 110, 115, 120)
Case 9
MyGraphic.DrawLine(DelPen, 100, 130, 85, 110)
MyGraphic.DrawLine(DelPen, 85, 110, 115, 120)
MyGraphic.DrawLine(Mypen, 100, 130, 105, 120)
MyGraphic.DrawLine(Mypen, 105, 120, 85, 115)
MyGraphic.DrawEllipse(Mypen, 85, 90, 30, 30)
Case 10
MyGraphic.DrawLine(DelPen, 100, 130, 105, 120)
MyGraphic.DrawLine(DelPen, 105, 120, 85, 115)
MyGraphic.DrawLine(Mypen, 100, 130, 120, 125)
MyGraphic.DrawLine(Mypen, 120, 125, 65, 115)
Case 11
MyGraphic.DrawLine(DelPen, 100, 130, 120, 125)
MyGraphic.DrawLine(DelPen, 120, 125, 65, 115)
MyGraphic.DrawLine(Mypen, 100, 130, 120, 130)
MyGraphic.DrawLine(Mypen, 120, 130, 85, 115)
Case 12
MyGraphic.DrawLine(DelPen, 120, 130, 85, 115)
MyGraphic.DrawLine(Mypen, 120, 130, 115, 115)
Case 13
MyGraphic.DrawLine(DelPen, 120, 130, 115, 115)
MyGraphic.DrawLine(Mypen, 120, 130, 145, 117)
MyGraphic.DrawEllipse(Mypen, 85, 90, 30, 30)
Case 14
MyGraphic.DrawLine(DelPen, 120, 130, 145, 117)
MyGraphic.DrawLine(Mypen, 120, 130, 175, 122)
Case 15
MyGraphic.DrawLine(DelPen, 120, 130, 175, 122)
MyGraphic.DrawLine(Mypen, 120, 130, 225, 126)
Case 16
MyGraphic.DrawLine(DelPen, 120, 130, 225, 126)
MyGraphic.DrawLine(Mypen, 120, 130, 260, 129)
Case 17
MyGraphic.DrawLine(DelPen, 120, 130, 260, 129)
MyGraphic.DrawLine(Mypen, 120, 130, 310, 133)
MyGraphic.DrawLine(Mypen, 295, 125, 285, 115)
MyGraphic.DrawLine(Mypen, 295, 135, 285, 145)
MyGraphic.DrawLine(Mypen, 305, 125, 315, 115)
MyGraphic.DrawLine(Mypen, 305, 135, 315, 145)
Case 18
MyGraphic.DrawLine(DelPen, 120, 130, 310, 133)
MyGraphic.DrawLine(DelPen, 295, 125, 285, 115)
MyGraphic.DrawLine(DelPen, 295, 135, 285, 145)
MyGraphic.DrawLine(DelPen, 305, 125, 315, 115)
MyGraphic.DrawLine(DelPen, 305, 135, 315, 145)
MyGraphic.DrawLine(Mypen, 120, 130, 295, 135)
MyGraphic.DrawEllipse(Mypen, 297, 109, 6, 6)
Case 19
MyGraphic.DrawLine(DelPen, 120, 130, 295, 135)
MyGraphic.DrawLine(Mypen, 120, 130, 275, 145)
Case 20
MyGraphic.DrawLine(DelPen, 120, 130, 275, 145)
MyGraphic.DrawLine(Mypen, 120, 130, 255, 165)
Case 21
MyGraphic.DrawLine(DelPen, 120, 130, 255, 165)
MyGraphic.DrawLine(Mypen, 120, 130, 235, 175)
Case 22
MyGraphic.DrawLine(DelPen, 120, 130, 235, 175)
MyGraphic.DrawLine(Mypen, 120, 130, 215, 185)
Case 23
MyGraphic.DrawLine(DelPen, 120, 130, 215, 185)
MyGraphic.DrawEllipse(DelPen, 297, 109, 6, 6)
MyGraphic.DrawLine(Mypen, 120, 130, 200, 190)
Case 24
Istep = 0
Timer1.Enabled = False
End Select

If Istep > 0 Then Istep = Istep + 1

M.Image = MyImage

End Sub

End Class

Code for Exit button:


Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
Private Istep As Integer
Private MyImage As Bitmap
Private MyGraphic As Graphics
Private Mypen As Pen
Private DelPen As Pen

Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal


eventArgs As System.EventArgs) Handles Command1.Click
Istep = 1
Timer1.Interval = 40
Timer1.Enabled = True
End Sub

Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal


eventArgs As System.EventArgs) Handles Command2.Click
Me.Close()
End Sub

Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal


eventArgs As System.EventArgs) Handles MyBase.Load
Timer1 = New Windows.Forms.Timer
MyImage = New Bitmap(M.Width, M.Height)
MyGraphic = Graphics.FromImage(MyImage)
Mypen = New Pen(Color.Black, 1)
DelPen = New Pen(Color.White, 1)

MyGraphic.DrawLine(Mypen, 300, 120, 300, 170)


MyGraphic.DrawLine(Mypen, 280, 130, 320, 130)
MyGraphic.DrawLine(Mypen, 300, 170, 280, 190)
MyGraphic.DrawLine(Mypen, 300, 170, 320, 190)
MyGraphic.DrawEllipse(Mypen, 285, 90, 30, 30)
MyGraphic.DrawLine(Mypen, 100, 120, 100, 170)
MyGraphic.DrawLine(Mypen, 80, 130, 120, 130)
MyGraphic.DrawLine(Mypen, 100, 170, 80, 190)
MyGraphic.DrawLine(Mypen, 100, 170, 120, 190)
MyGraphic.DrawEllipse(Mypen, 85, 90, 30, 30)
MyGraphic.DrawLine(Mypen, 120, 130, 200, 190)

M.Image = MyImage
End Sub

Private Sub M_Click(ByVal eventSender As System.Object, ByVal eventArgs


As System.EventArgs) Handles M.Click
Istep = 1
Timer1.Interval = 100
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal


eventArgs As System.EventArgs) Handles Timer1.Tick
MyGraphic = Graphics.FromImage(MyImage)
Select Case Istep
Case 1
MyGraphic.DrawLine(DelPen, 120, 130, 200, 190)
MyGraphic.DrawLine(Mypen, 120, 130, 180, 190)
Case 2
MyGraphic.DrawLine(DelPen, 100, 130, 120, 130)
MyGraphic.DrawLine(DelPen, 120, 130, 180, 190)
MyGraphic.DrawLine(Mypen, 100, 130, 118, 120)
MyGraphic.DrawLine(Mypen, 118, 120, 175, 190)
Case 3
MyGraphic.DrawLine(DelPen, 100, 130, 118, 120)
MyGraphic.DrawLine(DelPen, 118, 120, 175, 190)
MyGraphic.DrawLine(Mypen, 100, 130, 115, 110)
MyGraphic.DrawLine(Mypen, 115, 110, 165, 190)
Case 4
MyGraphic.DrawLine(DelPen, 100, 130, 115, 110)
MyGraphic.DrawLine(DelPen, 115, 110, 165, 190)
MyGraphic.DrawLine(Mypen, 100, 130, 105, 110)
MyGraphic.DrawLine(Mypen, 105, 110, 155, 180)
Case 5
MyGraphic.DrawLine(DelPen, 100, 130, 105, 110)
MyGraphic.DrawLine(DelPen, 105, 110, 155, 180)
MyGraphic.DrawLine(Mypen, 100, 130, 95, 110)
MyGraphic.DrawLine(Mypen, 95, 110, 145, 170)
Case 6
MyGraphic.DrawLine(DelPen, 100, 130, 95, 110)
MyGraphic.DrawLine(DelPen, 95, 110, 145, 170)
MyGraphic.DrawLine(Mypen, 100, 130, 85, 110)
MyGraphic.DrawLine(Mypen, 85, 110, 135, 160)
Case 7
MyGraphic.DrawLine(DelPen, 85, 110, 135, 160)
MyGraphic.DrawLine(Mypen, 85, 110, 125, 140)
Case 8
MyGraphic.DrawLine(DelPen, 85, 110, 125, 140)
MyGraphic.DrawLine(Mypen, 85, 110, 115, 120)
Case 9
MyGraphic.DrawLine(DelPen, 100, 130, 85, 110)
MyGraphic.DrawLine(DelPen, 85, 110, 115, 120)
MyGraphic.DrawLine(Mypen, 100, 130, 105, 120)
MyGraphic.DrawLine(Mypen, 105, 120, 85, 115)
MyGraphic.DrawEllipse(Mypen, 85, 90, 30, 30)
Case 10
MyGraphic.DrawLine(DelPen, 100, 130, 105, 120)
MyGraphic.DrawLine(DelPen, 105, 120, 85, 115)
MyGraphic.DrawLine(Mypen, 100, 130, 120, 125)
MyGraphic.DrawLine(Mypen, 120, 125, 65, 115)
Case 11
MyGraphic.DrawLine(DelPen, 100, 130, 120, 125)
MyGraphic.DrawLine(DelPen, 120, 125, 65, 115)
MyGraphic.DrawLine(Mypen, 100, 130, 120, 130)
MyGraphic.DrawLine(Mypen, 120, 130, 85, 115)
Case 12
MyGraphic.DrawLine(DelPen, 120, 130, 85, 115)
MyGraphic.DrawLine(Mypen, 120, 130, 115, 115)
Case 13
MyGraphic.DrawLine(DelPen, 120, 130, 115, 115)
MyGraphic.DrawLine(Mypen, 120, 130, 145, 117)
MyGraphic.DrawEllipse(Mypen, 85, 90, 30, 30)
Case 14
MyGraphic.DrawLine(DelPen, 120, 130, 145, 117)
MyGraphic.DrawLine(Mypen, 120, 130, 175, 122)
Case 15
MyGraphic.DrawLine(DelPen, 120, 130, 175, 122)
MyGraphic.DrawLine(Mypen, 120, 130, 225, 126)
Case 16
MyGraphic.DrawLine(DelPen, 120, 130, 225, 126)
MyGraphic.DrawLine(Mypen, 120, 130, 260, 129)
Case 17
MyGraphic.DrawLine(DelPen, 120, 130, 260, 129)
MyGraphic.DrawLine(Mypen, 120, 130, 310, 133)
MyGraphic.DrawLine(Mypen, 295, 125, 285, 115)
MyGraphic.DrawLine(Mypen, 295, 135, 285, 145)
MyGraphic.DrawLine(Mypen, 305, 125, 315, 115)
MyGraphic.DrawLine(Mypen, 305, 135, 315, 145)
Case 18
MyGraphic.DrawLine(DelPen, 120, 130, 310, 133)
MyGraphic.DrawLine(DelPen, 295, 125, 285, 115)
MyGraphic.DrawLine(DelPen, 295, 135, 285, 145)
MyGraphic.DrawLine(DelPen, 305, 125, 315, 115)
MyGraphic.DrawLine(DelPen, 305, 135, 315, 145)
MyGraphic.DrawLine(Mypen, 120, 130, 295, 135)
MyGraphic.DrawEllipse(Mypen, 297, 109, 6, 6)
Case 19
MyGraphic.DrawLine(DelPen, 120, 130, 295, 135)
MyGraphic.DrawLine(Mypen, 120, 130, 275, 145)
Case 20
MyGraphic.DrawLine(DelPen, 120, 130, 275, 145)
MyGraphic.DrawLine(Mypen, 120, 130, 255, 165)
Case 21
MyGraphic.DrawLine(DelPen, 120, 130, 255, 165)
MyGraphic.DrawLine(Mypen, 120, 130, 235, 175)
Case 22
MyGraphic.DrawLine(DelPen, 120, 130, 235, 175)
MyGraphic.DrawLine(Mypen, 120, 130, 215, 185)
Case 23
MyGraphic.DrawLine(DelPen, 120, 130, 215, 185)
MyGraphic.DrawEllipse(DelPen, 297, 109, 6, 6)
MyGraphic.DrawLine(Mypen, 120, 130, 200, 190)
Case 24
Istep = 0
Timer1.Enabled = False
End Select

If Istep > 0 Then Istep = Istep + 1

M.Image = MyImage

End Sub

End Class

Output:
•Advantages of VB.Net
Animation Feature:

• In VB.Net no drawing controls are provided; instead, user


is encouraged to use the GDI + Graphics service directly.
• Virtually, Everything Graphical that used to be in VB 6 has
disappeared in VB.Net

• The new graphical stuff in VB.Net is more powerful,


flexible and structured.

• Using ThreadPool Class, user can run 3 different


animations simultaneously on the same form.

•Future Scope of Animation


using VB.Net:

In the rapidly changing demands for more interactive and user


friendly Applications, Implementation of Animation and graphics
using VB.Net will increase the popularity of VB.Net framework
amongst the Developers. Ease of coding due to inheritance and
object oriented approach will make it suitable for programming
Complex applications.

Moreover, In development of websites and Web-services,


VB.Net has played an important role. Animation and Graphics
feature will urge more and more developers to use VB.Net as a
designing tool.

Anda mungkin juga menyukai