Sixem

.NET Animated TabControl

Aug 3rd, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.69 KB | None | 0 0
  1. 'Made by Mavamaarten~ @ HF
  2. Public Class AnimTab
  3.     Inherits TabControl
  4.     Dim OldIndex As Integer
  5.  
  6.     Private _Speed As Integer = 9
  7.     Property Speed As Integer
  8.         Get
  9.             Return _Speed
  10.         End Get
  11.         Set(ByVal value As Integer)
  12.             If value > 20 Or value < -20 Then
  13.                 MsgBox("Speed needs to be in between -20 and 20.")
  14.             Else
  15.                 _Speed = value
  16.             End If
  17.         End Set
  18.     End Property
  19.  
  20.     Sub New()
  21.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw, True)
  22.     End Sub
  23.  
  24.     Sub DoAnimationScrollLeft(ByVal Control1 As Control, ByVal Control2 As Control)
  25.         Dim G As Graphics = Control1.CreateGraphics()
  26.         Dim P1 As New Bitmap(Control1.Width, Control1.Height)
  27.         Dim P2 As New Bitmap(Control2.Width, Control2.Height)
  28.         Control1.DrawToBitmap(P1, New Rectangle(0, 0, Control1.Width, Control1.Height))
  29.         Control2.DrawToBitmap(P2, New Rectangle(0, 0, Control2.Width, Control2.Height))
  30.  
  31.         For Each c As Control In Control1.Controls
  32.             c.Hide()
  33.         Next
  34.  
  35.         Dim Slide As Integer = Control1.Width - (Control1.Width Mod _Speed)
  36.  
  37.         Dim a As Integer
  38.         For a = 0 To Slide Step _Speed
  39.             G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
  40.             G.DrawImage(P2, New Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height))
  41.         Next
  42.         a = Control1.Width
  43.         G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
  44.         G.DrawImage(P2, New Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height))
  45.  
  46.         SelectedTab = Control2
  47.  
  48.         For Each c As Control In Control2.Controls
  49.             c.Show()
  50.         Next
  51.  
  52.         For Each c As Control In Control1.Controls
  53.             c.Show()
  54.         Next
  55.     End Sub
  56.  
  57.     Protected Overrides Sub OnSelecting(ByVal e As System.Windows.Forms.TabControlCancelEventArgs)
  58.         If OldIndex < e.TabPageIndex Then
  59.             DoAnimationScrollRight(TabPages(OldIndex), TabPages(e.TabPageIndex))
  60.         Else
  61.             DoAnimationScrollLeft(TabPages(OldIndex), TabPages(e.TabPageIndex))
  62.         End If
  63.     End Sub
  64.  
  65.     Protected Overrides Sub OnDeselecting(ByVal e As System.Windows.Forms.TabControlCancelEventArgs)
  66.         OldIndex = e.TabPageIndex
  67.     End Sub
  68.  
  69.     Sub DoAnimationScrollRight(ByVal Control1 As Control, ByVal Control2 As Control)
  70.         Dim G As Graphics = Control1.CreateGraphics()
  71.         Dim P1 As New Bitmap(Control1.Width, Control1.Height)
  72.         Dim P2 As New Bitmap(Control2.Width, Control2.Height)
  73.         Control1.DrawToBitmap(P1, New Rectangle(0, 0, Control1.Width, Control1.Height))
  74.         Control2.DrawToBitmap(P2, New Rectangle(0, 0, Control2.Width, Control2.Height))
  75.  
  76.         For Each c As Control In Control1.Controls
  77.             c.Hide()
  78.         Next
  79.  
  80.         Dim Slide As Integer = Control1.Width - (Control1.Width Mod _Speed)
  81.  
  82.         Dim a As Integer
  83.         For a = 0 To -Slide Step -_Speed
  84.             G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
  85.             G.DrawImage(P2, New Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height))
  86.         Next
  87.         a = Control1.Width
  88.         G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
  89.         G.DrawImage(P2, New Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height))
  90.  
  91.         SelectedTab = Control2
  92.  
  93.         For Each c As Control In Control2.Controls
  94.             c.Show()
  95.         Next
  96.  
  97.         For Each c As Control In Control1.Controls
  98.             c.Show()
  99.         Next
  100.     End Sub
  101. End Class
Advertisement
Add Comment
Please, Sign In to add comment