beginners tutorial - Learn VB6
VB6 tutorial - Learn Advanced VB6
VB .NET - Learn Visual Basic .NET
Analysis - System analysis and Design tutorial for Software Engineering
You are here: Visual
Basic > Advanced VB6 tutorial
> Chapter 3
Important Properties of the TextBox Control
is one of the handiest and most popular
controls in a Windows application. It's a common approach to getting free-form
input from the user. You can manipulate a TextBox
contents and detect changes the user makes to the TextBox
through several properties:
- The HideSelection property is True by default
and it signifies that the user-highlighted contents of the
TextBox will not remain highlighted when focus shifts to another object.
If you want the highlighted contents to remain highlighted, just set
HideSelection to False.
- The MaxLength property determines the maximum
number of characters that the user can enter into the Text
property of the TextBox. If you set
MaxLength to 0, there is no limit on the number of characters that the
user can enter (well, up to 32K, that is)
- The Locked property allows the
TextBox to reject user changes but still allows the user to set focus to
the TextBox. Therefore, the user can scroll through
the contents of a TextBox without accidentally changing
anything. Contrast this to the Enabled property which doesn't allow the user to
set focus to the TextBox.
- The MultiLine property is only writable at design
time, although you can find out its value at runtime. MultiLine
is False by default, meaning that everything in the
TextBox control will appear on a single line. If MultiLine
is set to True, the TextBox will perform word-wrapping
and also break a typed line after a hard return.
- The PasswordChar property defines a character
that will appear on the screen in place of the actual characters in the
Text property. The underlying value of the Text property
still contains the actual characters typed by the user, but for each character
typed, only the password character will appear. Typically programmers set this
property to an asterisk (*) for TextBox controls that
represent the password on login screens. If you want to eliminate the
PasswordChar property for a TextBox, be careful
to erase its old value with your keyboard's Delete key instead of simply overwriting
it with the spacebar. A space in the PasswordChar property
will cause the user's input to appear as a series of blanks!
- The ScrollBars property is only writable at design
time, although you can check its value at runtime. The default value is None,
but you can also choose Horizontal, Vertical, or Both. Scrollbars enable the user
to scroll vertically through the contents of a multiple line
TextBox or horizontally through wide contents of TextBoxes.
- The SelText property assigns or returns the contents
of the currently selected text in a TextBox. If you
assign a string to SelText property in your code, you'll
replace the currently highlighted text with the contents of the new string and
deselect whatever had been selected before.
- The SelStart property is an integer value that
gives you the position of the first highlighted character in the
TextBox. It's zero-based. If there's no text currently selected,
SelStart will represent the current position of the text cursor within
the TextBox control. If you change the
SelStart property in your code, you'll deselect whatever text was highlighted
and move the text cursor to the position given by SelStart.
- The SelLength property is an integer that indicates
the number of selected characters in the TextBox. You
can change SelLength in your code in order to change
the number of selected characters. You can also deselect any highlighted characters
by setting SelLength to 0.
- The Text property is the TextBox
control's default property. You can set it at design time or runtime, and
you can also read it at runtime. The Text property
represents the current visible, editable (not necessarily visible or editable,
depending on the value of the Visible property, Enabled
and/or Locked) contents of the
TextBox. Since Text is the TextBox control's
default property, code such as
txtName = "Elizabeth"
would have the effect of setting the TextBox control's
Text property to "Elizabeth."
NOTE: TextBox controls have no
<< Previous | Contents
| Next >>