Older Version
Newer Version
JanetTerra
May 9, 2006
==Reviewing the Stylebits Parameters==
The four parameters of stylebits are AddBit, RemoveBit, AddExtendedBit, RemoveExtendedBit. For a review of these four parameters, and an introduction to Stylebits in general, please view [[Stylebits - Windows|Stylebits - Windows]].
===Line Wrapping===
//How can I get text to wrap in a textbox?// This question is frequently asked on the Liberty BASIC Forum. Line wrapping is easily achieved with a few stylebits.
[[code format="vb"]]
Nomainwin
WindowWidth=200
WindowHeight=160
text1$ = "STYLEBITS allows you to change the style of a Liberty BASIC
window or control."
text2$ = "Add to or edit this text."
Textbox #Main.txtbx, 0, 0, 190, 68
Stylebits #Main.txtbx, _WS_VSCROLL OR _ES_MULTILINE, _ES_AUTOHSCROLL, 0,
0
Statictext #Main, text2$, 5, 80, 190, 30
Open "LineWrap for LB" for Window_nf as #Main
Print #Main, "Trapclose [endMain]"
Print #Main, "Font Times_New_Roman 12 Bold"
Print #Main.txtbx, text1$
Wait
[endMain]
Close #Main
End
[[code]]
Go ahead and type in your own text. The text will wrap automatically as you type. It is possible to begin a new line in this word wrapping textbox, but you must use CTRL-ENTER rather than just ENTER.
If you don't like scroll bars, then use a resizable textbox. Substitute the above stylebits command with
[[code format="vb"]]
Stylebits #main.txtbx, _WS_THICKFRAME OR_ES_MULTILINE, _ES_AUTOHSCROLL, 0, 0
[[code]]
and let the user tug and pull the textbox all over the window. Be careful with this one. If your user shrinks the textbox and drags it behind another control, the textbox may become irretrievable. If you choose this effect, you may want to add some resize handling using the Locate and Refresh commands.
===Limiting Text Entry===
You can limit text length by omitting the vertical scroll bar. Without the ability to scroll, the textbox will only accept what can be visually seen. By carefully controlling the font size and the height of the textbox, user input can be contained.
[[code format="vb"]]
WindowWidth=200
WindowHeight=160
Nomainwin
text1$ = "Doc and Sleepy and Grumpy and Sneezy and"
text2$ = "Can you name the other 3?"
Textbox #main.txtbx, 0, 0, 190, 68
Stylebits #main.txtbx, _ES_MULTILINE, _ES_AUTOHSCROLL OR _ES_AUTOVSCROLL,
0, 0
Statictext #main, text2$, 5, 80, 190, 30
Open "LineWrap for LB" for Window_nf as #main
Print #main, "Trapclose [endDemo]"
Print #main, "Font Times_New_Roman 12 Bold"
Print #main.txtbx, text1$
Wait
[endDemo]
Close #main
End
[[code]]
By removing the multiline stylebit you can control the length of a single line of text input.
[[code format="vb"]]
Stylebits #main.txtbx, 0, _ES_AUTOHSCROLL OR _ES_AUTOVSCROLL, 0, 0
[[code]]
//The textbox is nice, but I really need a text editor. What stylebits will add word wrapping to the text editor//? Unfortunately, the text editor is a [[http://groups.yahoo.com/group/libertybasic/message/25061|widget]] and widgets do not respond well to stylebits. If your program requires a word wrapping text editor, consider downloading Alyce Watson's [[http://www.alycesrestaurant.com/Utilities.htm|Text Editor by API]]. This API modified textbox works just like a real text editor, it's compatible with Liberty BASIC v3.x as well as v4.x, and, best of all, like so many of [[http://www.alycesrestaurant.com/|Alyce's Liberty BASIC contributions]], it's **free**.
===Scrolling vs Wrapping===
It isn't always desirable to wrap text. If you anticipate text will extend beyond the limits of your textbox but you still want to keep the text on one line, consider adding a horizontal scroll bar.
[[code format="vb"]]
Stylebits #main.txtbx, _WS_HSCROLL, 0, 0, 0
[[code]]
===Textbox Borders===
Textbox borders respond to window style (_WS_) stylebits, but may require unique combinations. While
[[code format="vb"]]
Stylebits #main.gb, 0, _WS_BORDER, 0, 0
[[code]]
will remove the border of a graphic box, the same effect with a textbox can only be achieved with the removal of an extended style:
[[code format="vb"]]
Stylebits #main.txtbx, 0, _WS_BORDER, 0, _WS_EX_CLIENTEDGE
[[code]]
Thanks to
[[http://libertybasic.conforums.com/index.cgi?board=novice&action=display&num=1109874168&Reply=3|Mike Bradbury (See Reply #3)]] for posting this solution for removing the textbox border.
How about adding a horizontal scroll bar and removing the border? Here's a different look.
[[code format="vb"]]
Stylebits #main.txtbx, _WS_HSCROLL, _WS_BORDER, 0, _WS_EX_CLIENTEDGE
[[code]]
Rather than removing a border, stylebits might be used to draw a more defined border, giving a distinct 3 - D effect. _WS_EX_DLGMODALFRAME draws a raised border
[[code format="vb"]]
Stylebits #main.txtbx, 0, 0, _WS_EX_DLGMODALFRAME, 0
[[code]]
while _WS_EX_STATICEDGE draws a "step into" sunken border
[[code format="vb"]]
Stylebits #main.txtbx, 0, 0, _WS_EX_STATICEDGE, 0
[[code]]
===Restricting User Input===
Edit style (_ES_) stylebits can be used to restrict or modify user input.
Some examples include
* Numbers Only (Unfortunately, commas and periods are not accepted. Forget about using this style if decimals are involved.)
[[code format="vb"]]
Stylebits #main.txtbx, _ES_NUMBER, 0, 0, 0
[[code]]
* Password (The asterisk is the default. This character can be changed by using the SetPasswordChar function. Note that _ES_MULTILINE must be included as a RemoveBit parameter.)
[[code format="vb"]]
Stylebits #main.txtbx, _ES_PASSWORD, _ES_MULTILINE, 0, 0
[[code]]
* Uppercase / Lowercase (Converts all user input to uppercase / lowercase.)
[[code format="vb"]]
Stylebits #main.txtbx, _ES_UPPERCASE, 0, 0, 0
Stylebits #main.txtbx, _ES_LOWERCASE, 0, 0, 0
[[code]]
* Left / Center / Right Justify (Can be used in either single line textboxes or multiline textboxes.)
[[code format="vb"]]
Stylebits #main.txtbx, _ES_LEFT, 0, 0, 0
Stylebits #main.txtbx, _ES_CENTER, _ES_MULTILINE, 0, 0
Stylebits #main.txtbx, _ES_RIGHT, 0, 0, 0
[[code]]
* Read Only (Will not accept user input. Issuing a Disable command later in the program will 'gray out' any text in the textbox, but Enable will not reverse the _ES_READONLY style.)
[[code format="vb"]]
Stylebits #main.txtbx, _ES_READONLY, 0, 0, 0
[[code]]
===Other Stylebits with Textboxes===
The best way to see how textboxes can be altered with Stylebits is to experiment. You may well find that other combinations will create additional display and editing styles.