Advertisement
Jimi2000

Animation Form

May 1st, 2021
1,658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.44 KB | None | 0 0
  1. ' --------------------------------------------------------------------
  2. ' Class File: frmAnimation.vb
  3. '---------------------------------------------------------------------
  4.  
  5. Imports System.Drawing.Imaging
  6.  
  7. Public Class frmAnimation
  8.  
  9.     Private animation As Bitmap = Nothing
  10.     Private animationFrames As Integer = 0
  11.     Private currentFrame As Integer = 0
  12.     Private animationMaxLoops As Integer = 1
  13.     Private loops As Integer = 0
  14.  
  15.     Public Sub New()
  16.         InitializeComponent()
  17.         animation = My.Resources.icon_confirmation
  18.         PictureBox1.Size = animation.Size
  19.     End Sub
  20.  
  21.     Protected Overrides Sub OnShown(e As EventArgs)
  22.         MyBase.OnShown(e)
  23.         animationFrames = animation.GetFrameCount(New FrameDimension(animation.FrameDimensionsList(0)))
  24.         AnimateImage()
  25.     End Sub
  26.  
  27.     Public Sub AnimateImage()
  28.         If ImageAnimator.CanAnimate(animation) Then
  29.             ImageAnimator.Animate(animation, AddressOf OnFrameChanged)
  30.         End If
  31.     End Sub
  32.  
  33.     Private Sub OnFrameChanged(o As Object, e As EventArgs)
  34.         If currentFrame >= animationFrames Then
  35.             currentFrame = 0
  36.             loops += 1
  37.             If loops >= animationMaxLoops Then
  38.                 animationFrames = 0
  39.                 loops = 0
  40.                 animation?.Dispose()
  41.                 ImageAnimator.StopAnimate(animation, AddressOf OnFrameChanged)
  42.             End If
  43.         Else
  44.             PictureBox1.Invalidate()
  45.             currentFrame += 1
  46.         End If
  47.     End Sub
  48.  
  49.     Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
  50.         If animationFrames > 0 Then
  51.             ImageAnimator.UpdateFrames()
  52.             e.Graphics.DrawImage(animation, New Point(0, 0))
  53.         End If
  54.     End Sub
  55.  
  56.     Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
  57.         Close()
  58.     End Sub
  59. End Class
  60.  
  61. ' --------------------------------------------------------------------
  62. ' Designer File: frmAnimation.Designer.vb
  63. '---------------------------------------------------------------------
  64. <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
  65. Partial Class frmAnimation
  66.     Inherits System.Windows.Forms.Form
  67.  
  68.     <System.Diagnostics.DebuggerNonUserCode()>
  69.     Protected Overrides Sub Dispose(ByVal disposing As Boolean)
  70.         Try
  71.             If disposing AndAlso components IsNot Nothing Then
  72.                 components.Dispose()
  73.             End If
  74.         Finally
  75.             MyBase.Dispose(disposing)
  76.         End Try
  77.     End Sub
  78.  
  79.     Private components As System.ComponentModel.IContainer
  80.  
  81.     <System.Diagnostics.DebuggerStepThrough()>
  82.     Private Sub InitializeComponent()
  83.         Me.PictureBox1 = New System.Windows.Forms.PictureBox()
  84.         Me.btnClose = New System.Windows.Forms.Button()
  85.         Me.Panel1 = New System.Windows.Forms.Panel()
  86.         CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
  87.         Me.Panel1.SuspendLayout()
  88.         Me.SuspendLayout()
  89.         '
  90.         'PictureBox1
  91.         '
  92.         Me.PictureBox1.Location = New System.Drawing.Point(0, 0)
  93.         Me.PictureBox1.Name = "PictureBox1"
  94.         Me.PictureBox1.Size = New System.Drawing.Size(513, 333)
  95.         Me.PictureBox1.TabIndex = 80
  96.         Me.PictureBox1.TabStop = False
  97.         '
  98.         'btnClose
  99.         '
  100.         Me.btnClose.Anchor = System.Windows.Forms.AnchorStyles.Bottom
  101.         Me.btnClose.BackColor = System.Drawing.Color.FromArgb(CType(CType(48, Byte), Integer), CType(CType(48, Byte), Integer), CType(CType(48, Byte), Integer))
  102.         Me.btnClose.FlatAppearance.BorderSize = 0
  103.         Me.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat
  104.         Me.btnClose.Location = New System.Drawing.Point(213, 6)
  105.         Me.btnClose.Name = "btnClose"
  106.         Me.btnClose.Size = New System.Drawing.Size(116, 33)
  107.         Me.btnClose.TabIndex = 81
  108.         Me.btnClose.Text = "Close"
  109.         Me.btnClose.UseVisualStyleBackColor = False
  110.         '
  111.         'Panel1
  112.         '
  113.         Me.Panel1.Controls.Add(Me.btnClose)
  114.         Me.Panel1.Dock = System.Windows.Forms.DockStyle.Bottom
  115.         Me.Panel1.Location = New System.Drawing.Point(0, 333)
  116.         Me.Panel1.Name = "Panel1"
  117.         Me.Panel1.Size = New System.Drawing.Size(512, 46)
  118.         Me.Panel1.TabIndex = 82
  119.         '
  120.         'frmAnimation
  121.         '
  122.         Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!)
  123.         Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
  124.         Me.AutoSize = True
  125.         Me.BackColor = System.Drawing.Color.FromArgb(CType(CType(32, Byte), Integer), CType(CType(32, Byte), Integer), CType(CType(32, Byte), Integer))
  126.         Me.ClientSize = New System.Drawing.Size(512, 379)
  127.         Me.Controls.Add(Me.Panel1)
  128.         Me.Controls.Add(Me.PictureBox1)
  129.         Me.Font = New System.Drawing.Font("Segoe UI", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  130.         Me.ForeColor = System.Drawing.Color.White
  131.         Me.Name = "frmAnimation"
  132.         Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  133.         Me.Text = "frmAnimation"
  134.         CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
  135.         Me.Panel1.ResumeLayout(False)
  136.         Me.ResumeLayout(False)
  137.  
  138.     End Sub
  139.  
  140.     Private WithEvents PictureBox1 As PictureBox
  141.     Friend WithEvents btnClose As Button
  142.     Friend WithEvents Panel1 As Panel
  143. End Class
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement