TextBoxW Control
Provides an enhanced text box with support for Unicode, password characters, balloon tips, network address validation, drag-and-drop files, and OLE drag-and-drop.
Enumerations
TxtCharacterCasingConstants
Character casing constants.
| Constant | Value | Description |
|---|---|---|
| TxtCharacterCasingNormal | 0 | Normal (no case conversion) |
| TxtCharacterCasingUpper | 1 | Convert to uppercase |
| TxtCharacterCasingLower | 2 | Convert to lowercase |
TxtIconConstants
Balloon tip icon constants.
| Constant | Value | Description |
|---|---|---|
| TxtIconNone | 0 | No icon |
| TxtIconInfo | 1 | Information icon |
| TxtIconWarning | 2 | Warning icon |
| TxtIconError | 3 | Error icon |
TxtNetAddressFormatConstants
Network address format constants.
| Constant | Value | Description |
|---|---|---|
| TxtNetAddressFormatString | 0 | String format |
| TxtNetAddressFormatHostName | 1 | Host name format |
| TxtNetAddressFormatIPv4 | 2 | IPv4 format |
| TxtNetAddressFormatIPv6 | 3 | IPv6 format |
TxtNetAddressTypeConstants
Network address type constants.
| Constant | Value | Description |
|---|---|---|
| TxtNetAddressTypeNone | 0 | None |
| TxtNetAddressTypeIPv4 | 1 | IPv4 address |
| TxtNetAddressTypeIPv6 | 2 | IPv6 address |
| TxtNetAddressTypeIPv6WithScope | 3 | IPv6 address with scope |
| TxtNetAddressTypeDNS | 4 | DNS name |
| TxtNetAddressTypeNetBIOS | 5 | NetBIOS name |
| TxtNetAddressTypeUnspecified | 6 | Unspecified type |
| TxtNetAddressTypeNamedPipe | 7 | Named pipe |
| TxtNetAddressTypeEmailAddress | 8 | Email address |
| TxtNetAddressTypeURL | 9 | URL address |
| TxtNetAddressTypeURLKnownSuffix | 10 | URL with known suffix |
| TxtNetAddressTypeFriendlyDNS | 11 | Friendly DNS name |
| TxtNetAddressTypeDNSSimpleLabel | 12 | Single-label DNS name |
| TxtNetAddressTypeAddressMask | 13 | Address mask |
| TxtNetAddressTypeFileName | 14 | File name |
| TxtNetAddressTypeAny | 15 | Any address |
| TxtNetAddressTypeAnyLocal | 16 | Any local address |
| TxtNetAddressTypeIPv4MappedIPv6 | 17 | IPv4-mapped IPv6 address |
| TxtNetAddressTypeIPv4TranslatedIPv6 | 18 | IPv4-translated IPv6 address |
| TxtNetAddressTypeIPv4TeredoIPv6 | 19 | Teredo IPv6 address |
Properties
Name
Public Property Get Name() As StringReturns the name used to identify the object in code.
Tag
Public Property Get Tag() As String
Public Property Let Tag(ByVal Value As String)Stores extra data needed by the program.
Parent
Public Property Get Parent() As ObjectReturns the object that contains the object.
Container
Public Property Get Container() As Object
Public Property Set Container(ByVal Value As Object)Returns/sets the container of the object.
Left
Public Property Get Left() As Single
Public Property Let Left(ByVal Value As Single)Returns/sets the distance between the internal left edge of the object and the left edge of its container.
Top
Public Property Get Top() As Single
Public Property Let Top(ByVal Value As Single)Returns/sets the distance between the internal top edge of the object and the top edge of its container.
Width
Public Property Get Width() As Single
Public Property Let Width(ByVal Value As Single)Returns/sets the width of the object.
Height
Public Property Get Height() As Single
Public Property Let Height(ByVal Value As Single)Returns/sets the height of the object.
Visible
Public Property Get Visible() As Boolean
Public Property Let Visible(ByVal Value As Boolean)Returns/sets whether the object is visible.
ToolTipText
Public Property Get ToolTipText() As String
Public Property Let ToolTipText(ByVal Value As String)Returns/sets the tooltip text displayed when the mouse hovers.
WhatsThisHelpID
Public Property Get WhatsThisHelpID() As Long
Public Property Let WhatsThisHelpID(ByVal Value As Long)Returns/sets the associated context help ID.
DragIcon
Public Property Get DragIcon() As IPictureDisp
Public Property Let DragIcon(ByVal Value As IPictureDisp)
Public Property Set DragIcon(ByVal Value As IPictureDisp)Returns/sets the icon displayed during drag-and-drop operations.
DragMode
Public Property Get DragMode() As Integer
Public Property Let DragMode(ByVal Value As Integer)Returns/sets the drag mode (manual or automatic).
hWnd
Public Property Get hWnd() As LongPtrReturns the control handle.
hWndUserControl
Public Property Get hWndUserControl() As LongPtrReturns the UserControl handle.
Font
Public Property Get Font() As StdFont
Public Property Let Font(ByVal NewFont As StdFont)
Public Property Set Font(ByVal NewFont As StdFont)Returns/sets the font.
VisualStyles
Public Property Get VisualStyles() As Boolean
Public Property Let VisualStyles(ByVal Value As Boolean)Returns/sets whether visual styles are enabled. Requires comctl32.dll version 6.0 or later.
BackColor
Public Property Get BackColor() As OLE_COLOR
Public Property Let BackColor(ByVal Value As OLE_COLOR)Returns/sets the background color.
ForeColor
Public Property Get ForeColor() As OLE_COLOR
Public Property Let ForeColor(ByVal Value As OLE_COLOR)Returns/sets the foreground color.
Enabled
Public Property Get Enabled() As Boolean
Public Property Let Enabled(ByVal Value As Boolean)Returns/sets whether the object can respond to user events.
AllowDropFiles
Public Property Get AllowDropFiles() As Boolean
Public Property Let AllowDropFiles(ByVal Value As Boolean)Returns/sets whether drag-and-drop files are allowed.
OLEDragMode
Public Property Get OLEDragMode() As Integer
Public Property Let OLEDragMode(ByVal Value As Integer)Returns/sets the OLE drag mode.
OLEDragDropScroll
Public Property Get OLEDragDropScroll() As Boolean
Public Property Let OLEDragDropScroll(ByVal Value As Boolean)Returns/sets whether auto-scrolling is enabled during OLE drag-and-drop.
OLEDropMode
Public Property Get OLEDropMode() As OLEDropModeConstants
Public Property Let OLEDropMode(ByVal Value As OLEDropModeConstants)Returns/sets whether the object can act as an OLE drop target.
MousePointer
Public Property Get MousePointer() As CCMousePointerConstants
Public Property Let MousePointer(ByVal Value As CCMousePointerConstants)Returns/sets the type of mouse pointer displayed when the mouse hovers. See common enumerations.
MouseIcon
Public Property Get MouseIcon() As IPictureDisp
Public Property Let MouseIcon(ByVal Value As IPictureDisp)
Public Property Set MouseIcon(ByVal Value As IPictureDisp)Returns/sets the custom mouse icon.
MouseTrack
Public Property Get MouseTrack() As Boolean
Public Property Let MouseTrack(ByVal Value As Boolean)Returns/sets whether events are triggered when the mouse enters or leaves the control.
RightToLeft
Public Property Get RightToLeft() As Boolean
Public Property Let RightToLeft(ByVal Value As Boolean)Returns/sets the right-to-left display direction.
RightToLeftMode
Public Property Get RightToLeftMode() As CCRightToLeftModeConstants
Public Property Let RightToLeftMode(ByVal Value As CCRightToLeftModeConstants)Returns/sets the right-to-left mode. See common enumerations.
BorderStyle
Public Property Get BorderStyle() As Integer
Public Property Let BorderStyle(ByVal Value As Integer)Returns/sets the border style.
Text
Public Property Get Text() As String
Public Property Let Text(ByVal Value As String)Returns/sets the text content.
Default
Public Property Get Default() As Boolean
Public Property Let Default(ByVal Value As Boolean)Returns/sets whether this is the default button (activated by pressing Enter).
Alignment
Public Property Get Alignment() As AlignmentConstants
Public Property Let Alignment(ByVal Value As AlignmentConstants)Returns/sets the text alignment.
AllowOnlyNumbers
Public Property Get AllowOnlyNumbers() As Boolean
Public Property Let AllowOnlyNumbers(ByVal Value As Boolean)Returns/sets whether only numeric input is allowed.
Locked
Public Property Get Locked() As Boolean
Public Property Let Locked(ByVal Value As Boolean)Returns/sets whether editing is locked (scrolling and selection are still allowed).
HideSelection
Public Property Get HideSelection() As Boolean
Public Property Let HideSelection(ByVal Value As Boolean)Returns/sets whether the highlight of the selected text is hidden when the control loses focus.
PasswordChar
Public Property Get PasswordChar() As String
Public Property Let PasswordChar(ByVal Value As String)Returns/sets the password masking character.
UseSystemPasswordChar
Public Property Get UseSystemPasswordChar() As Boolean
Public Property Let UseSystemPasswordChar(ByVal Value As Boolean)Returns/sets whether to use the system default password character.
MultiLine
Public Property Get MultiLine() As Boolean
Public Property Let MultiLine(ByVal Value As Boolean)Returns/sets whether multi-line text input is accepted.
MaxLength
Public Property Get MaxLength() As Long
Public Property Let MaxLength(ByVal Value As Long)Returns/sets the maximum number of characters. 0 means no limit.
ScrollBars
Public Property Get ScrollBars() As Integer
Public Property Let ScrollBars(ByVal Value As Integer)Returns/sets the scroll bar style.
CueBanner
Public Property Get CueBanner() As String
Public Property Let CueBanner(ByVal Value As String)Returns/sets the cue banner text (displayed when the control is empty).
CueBannerAlways
Public Property Get CueBannerAlways() As Boolean
Public Property Let CueBannerAlways(ByVal Value As Boolean)Returns/sets whether the cue banner is always displayed (even when the control has focus).
CharacterCasing
Public Property Get CharacterCasing() As TxtCharacterCasingConstants
Public Property Let CharacterCasing(ByVal Value As TxtCharacterCasingConstants)Returns/sets the character casing conversion mode.
WantReturn
Public Property Get WantReturn() As Boolean
Public Property Let WantReturn(ByVal Value As Boolean)Returns/sets whether pressing Enter in a multi-line text box inserts a line break.
IMEMode
Public Property Get IMEMode() As CCIMEModeConstants
Public Property Let IMEMode(ByVal Value As CCIMEModeConstants)Returns/sets the Input Method Editor (IME) mode. See common enumerations.
NetAddressValidator
Public Property Get NetAddressValidator() As Boolean
Public Property Let NetAddressValidator(ByVal Value As Boolean)Returns/sets whether network address validation is enabled.
NetAddressType
Public Property Get NetAddressType() As TxtNetAddressTypeConstants
Public Property Let NetAddressType(ByVal Value As TxtNetAddressTypeConstants)Returns/sets the type of network address validation.
AllowOverType
Public Property Get AllowOverType() As Boolean
Public Property Let AllowOverType(ByVal Value As Boolean)Returns/sets whether overtype mode is allowed.
OverTypeMode
Public Property Get OverTypeMode() As Boolean
Public Property Let OverTypeMode(ByVal Value As Boolean)Returns/sets whether overtype mode is active.
Modified
Public Property Get Modified() As Boolean
Public Property Let Modified(ByVal Value As Boolean)Returns/sets whether the text has been modified.
TextLength
Public Property Get TextLength() As LongReturns the text length.
SelStart
Public Property Get SelStart() As Long
Public Property Let SelStart(ByVal Value As Long)Returns/sets the starting position of the selection.
SelLength
Public Property Get SelLength() As Long
Public Property Let SelLength(ByVal Value As Long)Returns/sets the length of the selection.
SelText
Public Property Get SelText() As String
Public Property Let SelText(ByVal Value As String)Returns/sets the text of the selection.
LeftMargin
Public Property Get LeftMargin() As Long
Public Property Let LeftMargin(ByVal Value As Long)Returns/sets the left margin.
RightMargin
Public Property Get RightMargin() As Long
Public Property Let RightMargin(ByVal Value As Long)Returns/sets the right margin.
Methods
Refresh
Public Sub Refresh()Forces a complete repaint of the object.
Copy
Public Sub Copy()Copies the selection to the clipboard.
Cut
Public Sub Cut()Cuts the selection to the clipboard.
Paste
Public Sub Paste()Pastes the clipboard contents into the control.
Clear
Public Sub Clear()Clears all text.
Undo
Public Sub Undo()Undoes the last operation.
CanUndo
Public Function CanUndo() As BooleanReturns whether an undo operation is available.
ResetUndoQueue
Public Sub ResetUndoQueue()Resets the undo queue.
OLEDrag
Public Sub OLEDrag()Initiates an OLE drag-and-drop operation.
GetLine
Public Function GetLine(ByVal LineIndex As Long) As StringGets the text content of the specified line.
GetLineCount
Public Function GetLineCount() As LongGets the number of text lines.
ScrollToLine
Public Sub ScrollToLine(ByVal LineIndex As Long)Scrolls to the specified line.
ScrollToCaret
Public Sub ScrollToCaret()Scrolls to the caret position.
CharFromPos
Public Function CharFromPos(ByVal X As Long, ByVal Y As Long) As LongGets the character index from coordinates.
GetLineFromChar
Public Function GetLineFromChar(ByVal CharIndex As Long) As LongGets the line number from a character index.
ShowBalloonTip
Public Sub ShowBalloonTip(ByVal Title As String, ByVal Text As String, ByVal Icon As TxtIconConstants)Displays a balloon tip.
HideBalloonTip
Public Sub HideBalloonTip()Hides the balloon tip.
ValidateNetAddress
Public Function ValidateNetAddress() As LongValidates the network address. Returns 0 if valid.
ShowNetAddressErrorTip
Public Sub ShowNetAddressErrorTip()Displays a network address error tip based on the validation result.
NetAddressFormat
Public Property Get NetAddressFormat() As TxtNetAddressFormatConstantsReturns the network address format.
NetAddressString
Public Property Get NetAddressString() As StringReturns the network address string.
NetAddressPortNumber
Public Property Get NetAddressPortNumber() As LongReturns the network address port number.
NetAddressPrefixLength
Public Property Get NetAddressPrefixLength() As LongReturns the network address prefix length.
Drag
Public Sub Drag(Optional ByRef Action As Variant)Starts, ends, or cancels a drag operation.
SetFocus
Public Sub SetFocus()Moves the focus to the control.
ZOrder
Public Sub ZOrder(Optional ByRef Position As Variant)Sets the Z-order.
Events
Click
Public Event Click()Occurs when the user clicks the control.
DblClick
Public Event DblClick()Occurs when the user double-clicks the control.
Change
Public Event Change()Occurs when the text content changes.
MaxText
Public Event MaxText()Occurs when the entered text exceeds the MaxLength limit.
DropFiles
Public Event DropFiles(ByVal Files As Variant)Occurs when files are dragged and dropped onto the control. Files is an array of file paths.
Scroll
Public Event Scroll()Occurs when the text scrolls.
ContextMenu
Public Event ContextMenu(ByVal X As Single, ByVal Y As Single, ByRef Handled As Boolean)Occurs when a context menu is requested. Set Handled to True to cancel the default menu.
PreviewKeyDown
Public Event PreviewKeyDown(KeyCode As Integer, Shift As Integer)Occurs before the KeyDown event, for preprocessing keyboard input.
PreviewKeyUp
Public Event PreviewKeyUp(KeyCode As Integer, Shift As Integer)Occurs before the KeyUp event.
KeyDown
Public Event KeyDown(KeyCode As Integer, Shift As Integer)Occurs when a keyboard key is pressed.
KeyUp
Public Event KeyUp(KeyCode As Integer, Shift As Integer)Occurs when a keyboard key is released.
KeyPress
Public Event KeyPress(KeyAscii As Integer)Occurs when an ANSI key is pressed and released.
MouseDown
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Occurs when a mouse button is pressed.
MouseMove
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Occurs when the mouse is moved.
MouseUp
Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)Occurs when a mouse button is released.
MouseEnter
Public Event MouseEnter()Occurs when the mouse enters the control area.
MouseLeave
Public Event MouseLeave()Occurs when the mouse leaves the control area.
OLECompleteDrag
Public Event OLECompleteDrag(Effect As Long)Occurs when an OLE drag-and-drop operation is completed.
OLEDragDrop
Public Event OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)Occurs when data is dropped during an OLE drag-and-drop operation.
OLEDragOver
Public Event OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)Occurs when data is dragged over the control during an OLE drag-and-drop operation.
OLEGiveFeedback
Public Event OLEGiveFeedback(Effect As Long, DefaultCursors As Boolean)Occurs during an OLE drag-and-drop operation to provide feedback.
OLESetData
Public Event OLESetData(Data As DataObject, DataFormat As Integer)Occurs when data is set during an OLE drag-and-drop operation.
OLEStartDrag
Public Event OLEStartDrag(Data As DataObject, AllowedEffects As Long)Occurs when an OLE drag-and-drop operation starts.
Code Examples
Basic Usage
' Set up a multi-line text box
With TextBoxW1
.MultiLine = True
.ScrollBars = 3
.MaxLength = 5000
.WantReturn = True
.CueBanner = "Please enter content..."
End With
' Use as a password box
With TextBoxW1
.PasswordChar = "*"
.UseSystemPasswordChar = True
.MaxLength = 20
End With
' Network address validation
TextBoxW1.NetAddressValidator = True
TextBoxW1.NetAddressType = TxtNetAddressTypeURL
Private Sub Command1_Click()
If TextBoxW1.ValidateNetAddress() = 0 Then
MsgBox "Address is valid: " & TextBoxW1.NetAddressString
Else
TextBoxW1.ShowNetAddressErrorTip
End If
End Sub
' Balloon tip
TextBoxW1.ShowBalloonTip "Input Error", "Please enter a valid email address", TxtIconError
' Drag-and-drop files
Private Sub TextBoxW1_DropFiles(ByVal Files As Variant)
Dim i As Long
For i = LBound(Files) To UBound(Files)
Debug.Print "File: " & Files(i)
Next i
End Sub