BB___TEXTEDITOR

=TEXTEDITOR= toc

Description
> A TEXTEDITOR is a //widget// (not a native JB control) that is similar to a window of type TEXT, and has essentially the same command set. Because it is a control, it can be placed on a window.

Texteditor Features

 * //**Edit Menu.**// Placing a texteditor on a window automatically places an Edit Menu on the menubar. (Don't use a Menu command to define an Edit menu; it will not work properly). Right-click a texteditor to pop up an Edit menu.
 * //**Scroll bars.**// Texteditors automatically add scroll bars. They cannot be removed or disabled in JB.
 * //**Word Wrap.**// You cannot wrap text with texteditors in JustBASIC. A line will be as long as necessary until a carriage return/line feed is encountered.
 * //**Enter key and Dialog Windows.**// Texteditors will not work properly on a window of type Dialog. This is because a texteditor uses the Enter key to add a carriage return and start a new line. With a window of type Dialog, the Enter key is trapped by the window and is used to activate a default button.

Texteditor Commands
The following commands (Methods) can be used with texteditor controls. See the individual pages for discussion. print #handle, "!autoresize" print #handle, "!cls" print #handle, "!copy" print #handle, "!cut" print #handle.ext, "!contents? varName$" print #handle.ext, "!disable" print #handle.ext, "!enable" print #handle.ext, "!font fontName pointsize" print #handle, "!line n string$" print #h, "!lines countVar" print #handle, "!modified? answer$" print #h, "!origin? columnVar rowVar " print #handle, "!paste" print #handle, "!selectall" print #handle, "!selection? selected$" print #handle.ext, "!setfocus"

Texteditor Variables
The following variables can be used with texteditor controls. See the individual pages for discussion. TexteditorColor$

Example
code format="lb" 'Using a texteditor to obtain multi-line input data. nomainwin

WindowWidth = 300 WindowHeight = 370

statictext #1 "Enter Contact Data: ", 10, 10, 100, 25 texteditor #1.te1 10, 40, 250, 120

button #1.btn1 "Click to continue...", [getContactData], UL 10, 200

open "" for window as #1 #1 "trapclose [quit]" #1.te1 "!setfocus" wait

[getContactData] #1.te1 "!contents? some$" if some$ = "" then notice "Please type something first.":wait

confirm "If contact info is correct, click 'Yes'." +chr$(13)+_ "Your data will be saved to the Database" +chr$(13)+chr$(13)+_ some$;y$

wait

[quit] close #1 end code

Useful Functions
Functions to move cursor programmatically to the start or end of the text code format="lb" global nLine nomainwin

WindowWidth = 448 WindowHeight = 355

UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)

texteditor #main.texteditor1, 6, 6, 272, 290 statictext #main.statictext2, "Move the cursor", 302, 51, 128, 25 button #main.button3, "to start of text", [button3Click], UL, 286, 76, 144, 25 button #main.button4, "to end of text", [button4Click], UL, 286, 116, 144, 25 button #main.button5, "add some text", [button5Click], UL, 286, 11, 144, 25 menu #main, "Edit"   '<--- Texteditor Menu can be moved but not removed.

open "Moving cursor in texteditor" for window as #main print #main, "trapclose [quit.main]"

print #main, "font ms_sans_serif 10" hndl$="#main.texteditor1"

wait

[quit.main] Close #main END

[button3Click]   'to start call toStart hndl$ #hndl$ "!setfocus" 'to show where cursor is   wait

[button4Click]   'to end call toEnd hndl$ #hndl$ "!setfocus" 'to show where cursor is   wait

[button5Click]   'add text call moreText hndl$ #hndl$ "!setfocus" 'to show where cursor is   wait

sub toStart hndl$ #hndl$ "!contents? save$" #hndl$ "!contents save$" end sub

sub toEnd hndl$ #hndl$ "!selectall" #hndl$ "!cut" #hndl$ "!paste" end sub

sub moreText hndl$ line$(0)="'Twas brillig, and the slithy toves. " line$(1)="Did gyre and gimble in the wabe; " line$(2)="All mimsy were the borogoves, " line$(3)="And the mome raths outgrabe." line$(4)=""

for i = 1 to int(rnd(0)*5)+1 #hndl$ line$(nLine) nLine = (nLine+1) mod 5 next

end sub code