DarkBanana Posted March 27, 2015 Posted March 27, 2015 (edited) Hey there, I'm trying to limit the user input to 20 characters every line. I tried this: #include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 300, 200) $edit = GUICtrlCreateEdit("Hello world", 10, 10, 280, 180, BitOR($ES_AUTOVSCROLL,$WS_VSCROLL,$ES_WANTRETURN)) _GUICtrlEdit_SetLimitText($edit, 20) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE But this only limits the number of characters for the whole Edit control. Is there a simple solution to this? Edited March 27, 2015 by DarkBanana
iamtheky Posted March 27, 2015 Posted March 27, 2015 (edited) #include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 300, 200) $edit = GUICtrlCreateEdit("Hello world", 10, 10, 280, 180, BitOR($ES_AUTOVSCROLL,$WS_VSCROLL,$ES_WANTRETURN)) _GUICtrlEdit_SetMargins($edit, BitOR($EC_LEFTMARGIN, $EC_RIGHTMARGIN), 0, 135) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Edited March 27, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
DarkBanana Posted March 27, 2015 Author Posted March 27, 2015 (edited) It works, thanks! But now I have another problem. If I read the edit data I only get a single line of characters without line breaks. #include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 300, 200) $edit = GUICtrlCreateEdit("Hello world", 10, 10, 280, 180, BitOR($ES_AUTOVSCROLL,$WS_VSCROLL,$ES_WANTRETURN)) _GUICtrlEdit_SetMargins($edit, $EC_RIGHTMARGIN, 0, 135) GUISetState() Do ToolTip(GuiCtrlRead($edit)) Until GUIGetMsg() = $GUI_EVENT_CLOSE Is it possible to force line breaks? For example: I copy this: "This is a line of text and there is no line break" and the edit looks like: This is a line of text and there is no line break But GuiCtrlRead() gives me: "This is a line of text and there is no line break" Edited March 27, 2015 by DarkBanana
reb Posted March 30, 2015 Posted March 30, 2015 Use this _GUICtrlEdit_SetMargins($edit, $EC_RIGHTMARGIN, 0, 10) ; 135) replace135 with 10 and it works REB MEASURE TWICE - CUT ONCE
iamtheky Posted March 30, 2015 Posted March 30, 2015 Wanting line breaks forced on the edit control is wrong. You have the data, pick one of the many hundreds of ways of parsing it. heres 1: $sString = "This is a line of text and there is no line break" msgbox(0, '' , _SplitStringByLineLength($sString , 20)) Func _SplitStringByLineLength($sString , $LineLen) $aString = stringsplit($sString , " " , 3) Local $TotalLen = 0 $sOutput = "" $LineLength = $LineLen for $i = 0 to ubound($aString) - 1 $CurLen = StringLen($aString[$i]) + 1 $NextLen = 0 If $i < ubound ($aString) - 1 then $NextLen = StringLen($aString[$i + 1]) If $TotalLen + $CurLen + $NextLen >= $LineLength Then $sOutput &= $aString[$i] & @CRLF $TotalLen = 0 Else $sOutput &= $aString[$i] & " " $TotalLen += $CurLen EndIf Next Return $sOutput EndFunc ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now