|
Post by wexhammer on Nov 27, 2019 13:45:29 GMT -5
Is it possible to limit the number of characters in a textedit control?
|
|
|
Post by Chris Iverson on Nov 27, 2019 15:31:05 GMT -5
Yes, although you need an API call to do so, LB doesn't have the feature natively.
First, get the Windows handle to the textbox. For example, if you have a textbox .tb in a window #main:
hText = hwnd(#main.tb)
Next, add this function to the end of your program:
Function SetTextboxLimit(hText, limit) CallDLL #user32, "SendMessageA",_ hText as ulong,_ _EM_LIMITTEXT as long,_ limit as long,_ 0 as long,_ SetTextboxLimit as long End Function
Finally, call this function, with the Windows handle of the textbox and the length you want to limit it to as parameters:
a = SetTextboxLimit(hText, 10) 'Limit the textbox to 10 characters
EDIT: Made a mistake. Corrected the code, and here's a full sample.
'Form created with the help of Freeform 3 v07-15-08 'Generated on Nov 27, 2019 at 14:32:01
[setup.main.Window]
'-----Begin code for #main
nomainwin WindowWidth = 550 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
TextboxColor$ = "white" textbox #main.tb, 5, 5, 100, 25
'-----End GUI objects code
open "untitled" for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]"
hText = hwnd(#main.tb) a = SetTextboxLimit(hText, 5)
[main.inputLoop] 'wait here for input event wait
[quit.main] 'End the program close #main end
Function SetTextboxLimit(hText, limit) CallDLL #user32, "SendMessageA",_ hText as ulong,_ _EM_LIMITTEXT as long,_ limit as long,_ 0 as long,_ SetTextboxLimit as long End Function
|
|
|
Post by wexhammer on Nov 28, 2019 6:17:48 GMT -5
Awsome thanks! Is this possible to use in liberty basics texteditor or would i need to use a richeditor from an api call instead?
|
|
|
Post by tsh73 on Nov 28, 2019 15:50:08 GMT -5
Obviously it is ordinary LB textbox in the example.
|
|