-->

Slide Animation in Tab Control VB.NET

03 2015

1. Create a New VB.NET Project with one form named as “Form1”.
2. Create a TabControl named as “TabControl1”.
3. Create 2 Timers named as “Timer1” and “Timer2” with Interval 10ms.
4. Create 2 Buttons named as “Button1” and “Button2” with text “Next” and “Back”.
5. Copy and paste the following code and Run to test.


Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer2.Enabled = True
End Sub

Dim tabPageOffset As Integer
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
tabPageOffset -= 100 ' Tweak to change speed
If tabPageOffset <= 0 Then tabPageOffset = 0 Timer1.Enabled = False End If TabControl1.SelectedTab.Controls(0).Left = tabPageOffset End Sub Private Sub TabControl1_Selecting(sender As Object, e As TabControlCancelEventArgs) Handles TabControl1.Selecting Dim CurrentTabSelected As Integer = TabControl1.SelectedIndex If TabControl1.SelectedIndex = 1 Then tabPageOffset = e.TabPage.ClientSize.Width ' Timer1.Enabled = True Else tabPageOffset_right_anim = 0 - e.TabPage.ClientSize.Width ' Timer2.Enabled = True End If End Sub Dim tabPageOffset_right_anim As Integer Private Sub Timer2_Tick(sender As System.Object, e As System.EventArgs) Handles Timer2.Tick tabPageOffset_right_anim += 100 ' Tweak to change speed If tabPageOffset_right_anim >= 0 Then
tabPageOffset_right_anim = 0
Timer2.Enabled = False
End If
TabControl1.SelectedTab.Controls(0).Left = tabPageOffset_right_anim
End Sub

Leave a Reply