Visual Basic: Scroll Boxes, Forms and
Controls
1. Horizontal and Vertical Scroll Box in Visual Basic (15 Marks)
What is a Scroll Box?
In Visual Basic, a scroll box refers to the scroll bars (horizontal and vertical) that allow users
to view content that is too large to be displayed in a control or window. These are
commonly used with controls like TextBox, PictureBox, ListBox, etc.
Horizontal Scroll Box:
- Allows left and right scrolling.
- Used when the content is wider than the visible area.
- VB Property: TextBox1.ScrollBars = Horizontal
Vertical Scroll Box:
- Allows up and down scrolling.
- Used when the content is taller than the control’s height.
- VB Property: TextBox1.ScrollBars = Vertical
Both Scroll Bars:
- Use TextBox1.ScrollBars = Both to enable both scroll bars.
Controls That Support Scroll Bars:
- TextBox (Multiline)
- ListBox
- RichTextBox
- PictureBox (within a scrollable container like Panel)
2. Forms and Controls in Visual Basic (15 Marks)
Forms in Visual Basic:
- A Form is a window or screen where the user interacts with the application.
- It acts as a container for controls.
- Example: Form1.Show()
Purpose of Forms:
- Create GUI (Graphical User Interface).
- Hold and manage controls.
- Handle user input and events.
Controls in Visual Basic:
Controls are interactive elements placed on forms to accept input, display output, and
interact with users.
Common VB Controls:
- Label: Displays static text
- TextBox: Takes input from the user
- Button: Performs an action on click
- CheckBox: Allows multiple selections
- RadioButton: Allows a single selection
- ListBox: Displays a list of items
- ComboBox: Drop-down list
- PictureBox: Displays images
- Timer: Performs actions at regular intervals
Example: Simple Login Form in VB
Controls used:
- 2 Labels (Username, Password)
- 2 TextBoxes
- 1 Button (Login)
Code:
If TextBox1.Text = "admin" And TextBox2.Text = "1234" Then
MsgBox("Login Successful")
Else
MsgBox("Invalid Login")
End If
Conclusion:
In Visual Basic:
- Scroll boxes help users view content that doesn't fit in the visible area.
- Forms act as the user interface, and controls allow user interaction and input.
Both are essential for building user-friendly GUI applications.