Older Version Newer Version

JanetTerra 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 .

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.

 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

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

 Stylebits #main.txtbx, _WS_THICKFRAME OR_ES_MULTILINE, _ES_AUTOHSCROLL, 0, 0 

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.

 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

By removing the multiline stylebit you can control the length of a single line of text input.

 Stylebits #main.txtbx, 0, _ES_AUTOHSCROLL OR _ES_AUTOVSCROLL, 0, 0 

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 widget and widgets do not respond well to stylebits. If your program requires a word wrapping text editor, consider downloading Alyce Watson's 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 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.

 Stylebits #main.txtbx, _WS_HSCROLL, 0, 0, 0 

Textbox Borders


Textbox borders respond to window style (_WS_) stylebits, but may require unique combinations. While

 Stylebits #main.gb, 0, _WS_BORDER, 0, 0 

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:

 Stylebits #main.txtbx, 0, _WS_BORDER, 0, _WS_EX_CLIENTEDGE 

Thanks to

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.

 Stylebits #main.txtbx, _WS_HSCROLL, _WS_BORDER, 0, _WS_EX_CLIENTEDGE 

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

 Stylebits #main.txtbx, 0, 0, _WS_EX_DLGMODALFRAME, 0 

while _WS_EX_STATICEDGE draws a "step into" sunken border

 Stylebits #main.txtbx, 0, 0, _WS_EX_STATICEDGE, 0 

Restricting User Input


Edit style (_ES_) stylebits can be used to restrict or modify user input.

Some examples include


 Stylebits #main.txtbx, _ES_NUMBER, 0, 0, 0 


 Stylebits #main.txtbx, _ES_PASSWORD, _ES_MULTILINE, 0, 0 


 Stylebits #main.txtbx, _ES_UPPERCASE, 0, 0, 0 
Stylebits #main.txtbx, _ES_LOWERCASE, 0, 0, 0


 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


 Stylebits #main.txtbx, _ES_READONLY, 0, 0, 0 

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.