Color Statements for Controls

- Alyce Alyce

Color Statements for Controls | Color Statements | Usage | Named Colors | Controls that can be colored. | Demo

Color Statements


Windows and controls can be colored using color statements. The color statements assign named Liberty BASIC colors to special variables. The possible special variables are:

TextboxColor$
TexteditorColor$
ListboxColor$
ComboboxColor$
ForegroundColor$
BackgroundColor$

If no color statements are used, then default colors will appear on windows and controls. Color statements require named Liberty BASIC colors. Case doesn't matter in the color names, but it DOES matter in the variable names. TextboxColor$ is correct. TEXTBOXCOLOR$ is incorrect and will not be recognized as a statement by Liberty BASIC. If Liberty BASIC doesn't recognize the color name in the color statement, then it will use the default value for that color.

Usage


A color statement is accomplished by assigning values to the special Liberty BASIC variables as below.

TextboxColor$ = "Red"
TexteditorColor$ = "blue"
ListboxColor$ = "buttonface"
ComboboxColor$ = "GREEN"
ForegroundColor$ = "YelLow"
BackgroundColor$ = "uh oh"

The BackgroundColor$ used by Liberty BASIC in the example above will be the default color, because Liberty BASIC doesn't recognize "uh oh" as a named color. Note that the color names are not case-sensitive, but the variable names, like TextboxColor$, as variables, must be in the correct case.

Named Colors


The named Liberty BASIC colors include the following 16 colors, plus a color that varies with the user's color scheme called "buttonface".

colors16.gif
plus: buttonface (varies with user's color scheme)

It is possible to have only one ForegroundColor$ for each window, so all text, statictext, radiobutton, checkbox and groupbox captions will appear in the designated ForegroundColor$.

It is also possible to have only one BackgroundColor$ for each window. Since statictext uses the designated BackgroundColor$ for its color, it is not possible to have different colors for separate statictext controls on a single window. This also applies to groupboxes, radiobuttons and checkboxes.

Buttons ignore color statements. Buttons are always filled with the color set by the user's system value for buttonface. This color is defined by Liberty BASIC as "buttonface" and it changes depending upon the user's color scheme.

Controls that can be colored.


Controls that can be colored individually are:

Textbox, with TextboxColor$
Texteditor, with TexteditorColor$
Listbox, with ListboxColor$
Combobox, with ComboboxColor$

If a single control color statement is issued before the controls are created, then all controls of that type will be the same color. In the following example, all three textboxes will be cyan-colored.

TextboxColor$="cyan"
textbox #main.1, 10,10,100,24
textbox #main.2, 10,40,100,24
textbox #main.3, 10,70,100,24

It is possible to have several controls of the same type, each with its own unique color. To accomplish this, issue a new color statement before the statement to create each control, and the control will use the designated color. Do this for each color change desired. The following code will produce three textboxes, one green, one blue and one red.

TextboxColor$="green"
textbox #main.1, 10,10,100,24
TextboxColor$="blue"
textbox #main.2, 10,40,100,24
TextboxColor$="red"
textbox #main.3, 10,70,100,24

Demo


coloredcontrols.jpg

The following self-contained demo shows how to have colorful controls in Liberty BASIC windows.

nomainwin
 
WindowWidth=600:WindowHeight=400
 
list$(1)="First"
list$(2)="Second"
list$(3)="Third"
 
ForegroundColor$="yellow"
BackgroundColor$="darkcyan"
 
button #main.quit, "Quit",[quit],UL,450,320,100,24
 
groupbox #main.g, "Groupbox",120,10,120,120
radiobutton #main.r, "Radiobutton",[quit],[quit],130,40,110,30
checkbox #main.c, "Checkbox",[quit],[quit],130,80,110,30
statictext #main.s, "Statictext",10,100,100,24
 
TextboxColor$="green"
textbox #main.1, 10,10,100,24
 
TextboxColor$="blue"
textbox #main.2, 10,40,100,24
 
TextboxColor$="red"
textbox #main.3, 10,70,100,24
 
TexteditorColor$="darkgreen"
texteditor #main.4, 10,140,200,160
 
TexteditorColor$="darkblue"
texteditor #main.5, 220,140,200,160
 
ComboboxColor$="darkred"
combobox #main.c1, list$(),[quit],10,320,200,200
 
ComboboxColor$="darkpink"
combobox #main.c2, list$(),[quit],220,320,200,200
 
ListboxColor$="brown"
listbox #main.b1, list$(),[quit],250,20,100,100
 
ListboxColor$="darkred"
listbox #main.b2, list$(),[quit],360,20,100,100
 
 
open "Color Demo" for window_nf as #main
 
#main.1 "One";
#main.2 "Two";
#main.3 "Three";
#main.4 "Four";
#main.5 "Five";
#main.c1 "selectindex 1"
#main.c2 "selectindex 2"
#main.b1 "selectindex 1"
#main.b2 "selectindex 2"
 
#main "trapclose [quit]"
wait
 
[quit]
close #main:end