Some basic properties of Label and TextBox control in Visual Basic 6 are explained in this lesson.
Properties of label
- Appearance: Sets whether or not a label is painted with 3D effects.
- BackStyle: Sets whether the background of the label is transparent or opaque.
- Caption: Sets the text to be displayed.
Properties of TextBox
- Enabled: Determines whether the TextBox can respond to user-generated events.
- Locked: Determines whether the TextBox can be edited. You can prevent the user from changing the content of the TextBox.
- MultiLine: Indicates whether it can accept multiple lines of text.
- Alignment: Aligns the text to left justify, right justify or center.
- MaxLength: Sets the maximum number of characters that can be entered. If you want to set a limit on the number of characters that the user can enter, you can do it very easily with the MaxLength property.
- PasswordChar: This property is useful for a password program. For example, if u enter ‘*’ as a value to this property, whatever character you type in, it will be shown as ‘*’.
- ScrollBars: Says whether the TextBox has a scroll bar.
- ToolTipText: Sets the text displayed when the mouse is paused over the control.
Example Programs
There are four example projects attached at the top of this post that demonstrate some of the available properties.
Note: The Password Program has used msgbox for output. To understand this program, you first need to learn about msgbox which is described in a later lesson.
Run-Time properties of TextBox
Run-time properties are not visible in the Properties Window. You need to write code to set run-time properties.
SelStart
Sets the position of the blinking cursor that appears in the TextBox Control. When the cursor is at the beginning of the text, the value of SelStart is 0. When its at the end of the text, it returns Len(text1.text). ‘Len’ is a string function that returns the length of the text or the number of characters in the text. Set SelStart property to move the cursor in the TextBox.
Example
Private Sub Form_Load() Text1.Text = "Visual" Text1.SelStart = 3 End Sub
Output
SelLength
Sets the number of characters that has been selected or highlighted.
Example
Private Sub Form_Load() Text1.Text = "Visual" Text1.SelLength = 3 End Sub
Output
SelText
Sets or returns the text that is currently selected or highlighted.
Example
Private Sub Form_Load() Text1.Text = "Visual" Text1.SelLength = 3 Text1.Text = Text1.SelText End Sub