Jump to content

Recommended Posts

Posted (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 by DarkBanana
Posted (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 by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted (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 by DarkBanana
Posted

Use this  _GUICtrlEdit_SetMargins($edit, $EC_RIGHTMARGIN, 0, 10) ; 135)

replace135 with 10 and it works

REB

MEASURE TWICE - CUT ONCE

Posted

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

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...