Creates an Ocx TextBox control in the current active form, window, or dialog.
Ocx TextBox name [= text$] [, id] [, x, y, b, h] [, style%]
text$ | : control text |
id% | : control identifier |
x, y, b, h | : integer expression |
style% | : the control styles |
A TextBox control, sometimes called an edit field or edit control, displays information entered at design time, entered by the user, or assigned to the control in code at run time.
To display multiple lines of text in a TextBox control, set the MultiLine property to True. If a multiple-line TextBox doesn't have a horizontal scroll bar, text wraps automatically even when the TextBox is resized. To customize the scroll bar combination on a TextBox, set the ScrollBars property.
Scroll bars will always appear on the TextBox when its MultiLine property is set to True, and its ScrollBars property is set to anything except None (0).
If you set the MultiLine property to True, you can use the Alignment property to set the alignment of text within the TextBox. The text is left-justified by default. If the MultiLine property is False, setting the Alignment property has no effect.
Alignment | Appearance | BackColor | BorderStyle | Enabled | Font | FontBold | FontItalic | FontStrikethru | FontUnderline | FontName | FontSize | ForeColor | Height | HelpContextID | HideSelection | hWnd | Index | Left | MaxLength | MouseCursor | MouseIcon | MousePointer | MultiLine | Name | Parent | PassWordChar | ReadOnly | ScrollBars | SelLength | SelStart | SelText | TabStop | Tag | Text | Top | ToolTiptext | Visible | WantSpecial | WhatsThisHelpID | Width
DoClick | CharFromLine | ColFromChar | GetLineFromChar | LineCount | LineFromChar | Move | Refresh | RowFromChar | SetFont | Scroll | ScrollCaret | TextHeight | TextWidth | ZOrder
Change | Click | DblClick | GotFocus | LostFocus | KeyDown, Keyup | KeyPress | MouseDown | MouseUp | MouseMove | SelChange
OpenW Hidden 1
With Win_1
.ScaleMode = basTwips
.BackColor = colBtnFace
.Caption = "Label & TextBox"
.Height = 3950
.Left = 60
.Top = 345
.Width = 4000
EndWith
Win_1.Show
OcxScale = 1
Ocx Label lb1 = "Lbl&1:", 360, 90, 2000, 375
Ocx TextBox Text1 = "Text1", 360, 480, 3135, 375
Ocx Label lb2 = "Lbl&2:", 360, 900, 2000, 375
Ocx TextBox Text2 = "Text2", 360, 1200, 3135, 375
Ocx Label lb3 = "Lbl&3:", 360, 1700, 2000, 375
Ocx TextBox Text3 = "Text3", 360, 2040, 3135, 375
Ocx Command cmdClear = "&Clear Fields", 360, 2880, 1455, 375
.Default = True
Ocx Command cmdQuit = "&Quit", 2160, 2880, 1095, 375
.Cancel = True
Text1.SetFocus
Do
Sleep
Until Me Is Nothing
Sub cmdQuit_Click
PostMessage Win_1.hWnd, WM_CLOSE, 0, 0
End Sub
Sub cmdClear_Click
ClearTextboxes(cmdClear.Parent)
End Sub
Sub ClearTextboxes(frm As Form)
Local EditField As Control
For Each EditField In frm.Controls
If TypeOf(EditField) Is TextBox Then
EditField.Text = ""
End If
Next
End Sub
OCX Textboxes come with certain control key combinations as default. These are:
Ctrl-C | Copy |
Ctrl-H | Backspace |
Ctrl-I | Tab |
Ctrl-J & Ctrl-M | Carriage Return and Line Feed |
Ctrl-V | Paste |
Ctrl-X | Cut |
Ctrl-Z | Undo/Redo |
Ctrl-Delete | Deletes to the end of the line |
Ctrl-End | Bottom of the box |
Ctrl-Home | Top of the box |
It is possible to change the length and position of tab stops (entered using Ctrl-Tab or Tab if WantSpecial is set accordingly) using the EM_SETTABSTOPS message as is shown in the example below:
// Set the regular tab interval
Local stab% = 16
// Set the customised tab intervals
Local mtabs%() : Array mtabs%() = Mki$(4, 20, 32, 60, 75)
OpenW 1
// NOTE: For Tab stops to work, the TextBox MUST be Multiline
// Draw TextBox and set to regular tabs
Text 10, 10, "Tab stops at regular intervals"
Ocx TextBox txt1 = "", 10, 30, 300, 200 : txt1.MultiLine = True : txt1.WantSpecial = 2
~SendMessage(txt1.hWnd, EM_SETTABSTOPS, 1, V:stab%)
txt1.Text = "A"#9"A"#9"A"#9"A"#9"A"#9"A"#9"A"
Text 10, 260, "Tab stops at customised intervals"
// Draw TextBox and set to regular tabs (note, textbox MUST be Multiline)
// The number in ~SendMessage should equal the number of elements in mtabs%()
// All tabs after the last custom one are equal to the last value entered.
Ocx TextBox txt2 = "", 10, 280, 300, 200 : txt2.MultiLine = True : txt2.WantSpecial = 2
~SendMessage(txt2.hWnd, EM_SETTABSTOPS, 5, V:mtabs%(0))
txt2.Text = "A"#9"A"#9"A"#9"A"#9"A"#9"A"#9"A"
Do : Sleep : Until Win_1 Is Nothing
It is also possible to set Cue Banners (as long as Common Controls v6 or higher are enabled through the Manifest). An example of using these is below:
Const EM_SETCUEBANNER = $1501
OpenW 1
Ocx TextBox txt1 = "", 10, 10, 100, 15 : txt1.BorderStyle = 1
Ocx TextBox txt2 = "", 10, 30, 100, 15 : txt2.BorderStyle = 1
Local st$ = StrW("[Cue Banner]") // Creates a Unicode string
Trace Len(st$)
~SendMessage(txt1.hWnd, EM_SETCUEBANNER, True, V:st$) // True means that Cue Banner visible if textbox has focus
~SendMessage(txt2.hWnd, EM_SETCUEBANNER, False, V:st$) // True means that Cue Banner is not visible if textbox has focus
Do : Sleep : Until Win_1 Is Nothing
Function StrW(vnt As Variant, Optional skip?) As String // v3
// Acknowledgements to Sjouke Hamstra
Dim a$, BSTR As Register Long : BSTR = {V:vnt + 8}
a$ = StrPeek(BSTR, {BSTR - 4}) : If Not skip? Then a$ = a$ & Chr(0)
Return a$
EndFunction
[Reported by James Gaite, 06/11/2022]Animation, CheckBox, ComboBox, Command, CommDlg, Form, Frame, Image, ImageList, Label, ListBox, ListView, MonthView, Option, ProgressBar, RichEdit, Scroll, Slider, StatusBar, TabStrip, Timer, TrayIcon, TreeView, UpDown
{Created by Sjouke Hamstra; Last updated: 06/11/2022 by James Gaite}