This VB.NET Windows Forms program demonstrates how to move the text “Pune University” continuously from left to right and vice versa using a Timer control. It helps students understand animation and control movement in Windows Forms.
Slip 2 Q.A) Write a VB.Net program to move the text “Pune University” continuously from Left to Right and Vice Versa. 15 Marks
Answer:
Algorithm / Logic
- Start the application.
- Design a Windows Form and place a Label control with the text “Pune University” on it.
- Add a Timer control to the form and set its
Intervalproperty. - Initialize a direction variable to control the movement of the label.
- Start the Timer when the form loads or when a button is clicked.
- On each Timer tick:
- Move the label towards the right by increasing its
Leftproperty. - When the label reaches the right boundary of the form, change the direction.
- Move the label towards the left by decreasing its
Leftproperty.
- Move the label towards the right by increasing its
- Repeat the process continuously to achieve left-to-right and right-to-left movement.
- Stop the application.
Source Code
Public Class Form1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Label1.Left >= Me.Width Then
Label1.Left = -100
Else
Label1.Left = Label1.Left + 10
End If
End Sub
End Class
FAQ Section
Q1. What is VB.NET?
VB.NET is an object-oriented programming language used to develop Windows, web, and database applications on the .NET framework.
Q2. What is a Windows Forms application?
It is a type of .NET application used to create graphical user interface (GUI) based desktop programs.
Q3. Which control is used to display text in this program?
A Label control is used to display the text.
Q4. What is the purpose of the Timer control?
The Timer control is used to execute code repeatedly at a fixed time interval.
Q5. What does the Interval property of the Timer specify?
It specifies the time in milliseconds between two consecutive Timer ticks.