TEXTEDITOR
Jump to navigation
Jump to search
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.
Syntax
- TEXTEDITOR #handle.ext, x, y, wide, high
Hints
Texteditor Features
- Edit Menu. Placing a text-editor on a window automatically places an Edit Menu on the menu-bar. (Don't use a Menu command to define an Edit menu; it will not work properly). Right-click a text-editor to pop up an Edit menu.
- Scroll bars. Text-editors automatically add scroll bars. They cannot be removed or disabled in JB.
- Word Wrap. You cannot wrap text with text-editors in Just BASIC. A line will be as long as necessary until a carriage return/line feed is encountered.
- Enter key and Dialog Windows. Text-editors will not work properly on a window of type Dialog. This is because a text-editor 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 text-editor 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 text-editor controls. See the individual pages for discussion.
Example
'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
Useful Procedures
Functions to move cursor programmatically to the start or end of the text
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