TextBox controls offer a natural way for users to enter a value in your program. For this reason, they tend to be the most frequently used controls in the majority of Windows applications. TextBox controls, which have a great many properties and events, are also among the most complex intrinsic controls. In this section, I guide you through the most useful properties of TextBox controls and show how to solve some of the problems that you’re likely to encounter.
The Text property is the one you’ll reference most often in code, and conveniently it’s the default property for the TextBox control. Three other frequently used properties are these:
When you want to append text to a TextBox control, you should use the following code (instead of using the concatenation operator) to reduce flickering and improve performance:
Text1.SelStart = Len(Text1.Text)
Text1.SelText = StringToBeAdded
One of the typical operations you could find yourself performing with these properties is selecting the entire contents of a TextBox control. You often do it when the caret enters the field so that the user can quickly override the existing value with a new one, or start editing it by pressing any arrow key:
Private Sub Text1_GotFocus()
Text1.SelStart = 0
‘ A very high value always does the trick.
Text1.SelLength = 9999
End Sub
Always set the SelStart property first and then the SelLength or SelText properties. When you assign a new value to the SelStart property, the other two are automatically reset to 0 and an empty string respectively, thus overriding your previous settings.
The selected text can be copied to the Clipboard by using SelText:
Clipboard.SelText text, [format]
In the above syntax, text is the text that has to be placed into the Clipboard, and format has three possible values.
1. VbCFLink – conversation information
2. VbCFRTF – Rich Text Format
3. VbCFText – Text
We can get text from the clipboard using the GetText() function this way:
Clipboard.GetText ([format])
The following Figure summarizes the common TextBox control’s properties and methods.

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Back
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 