Jump to content

Toggle Line Wrap with CtrlEdit


 Share

Recommended Posts

Hello,

I tested a lot and searched lots of places. But this doesn't want to work! Anyone knows how to do this?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 242, 298, 302, 218)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 225, 241,BitOR($ES_WANTRETURN,0x50200104))
GUICtrlSetData(-1, StringFormat("This is a very very very very very very very very very very very very very long line to see if it toggles wrap.\r\n\r\nLine 2\r\nLine 3\r\n\r\nAnother very very very very very very very very very very very very very long line to see if it toggles wrap."))
$Button1 = GUICtrlCreateButton("Toggle", 8, 264, 227, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$wrap = 0
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            If $wrap = 0 Then
                GUICtrlSetStyle($Edit1,BitOR($ES_WANTRETURN,0x50300104))
                $wrap = 1
            Else
                GUICtrlSetStyle($Edit1,BitOR($ES_WANTRETURN,0x50200104))
                $wrap = 0
            EndIf
    EndSwitch
WEnd
Link to comment
Share on other sites

I tried several ideas I had too, but no luck....

Maybe it's because of what is said in the help:

GUICtrlSetStyle

Remarks

Some styles cannot be changed dynamically, check MSDN documentation. $CBS_UPPERCASE combo style is one example.

Edited by jmon
Link to comment
Share on other sites

I created a word wrap toggle function very successfuly by destroying the edit and recreating it. While it may seem inefficient, I also have a toggle toolbar and a toggle status (label), so the edit needs to be resized quite a lot. You need to get the size of the edit control and copy the text before you do this. I also undo the last action to preserve undo history and set selected text and scroll bar position. I would like to show you, but pulling it out of 2000 lines of code and creating an example would take me too long ATM, so I'm afraid you'll have to try it out for yourself.

Edited by czardas
Link to comment
Share on other sites

Hello,

Tnx everyone for the info.

I was thinking about deleting it n creating it again but I thought there might be a cleaner way.

Here is an example by deleting and creating. Getting the position and size of the editor control before deleting is only for if your gui or edit ctrl needs to change size but I included that too just in case.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 242, 298, 302, 218)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 225, 241,BitOR($ES_WANTRETURN,0x50200104))
GUICtrlSetData(-1, StringFormat("This is a very very very very very very very very very very very very very long line to see if it toggles wrap.rnrnLine 2rnLine 3rnrnAnother very very very very very very very very very very very very very long line to see if it toggles wrap."))
$Button1 = GUICtrlCreateButton("Toggle", 8, 264, 227, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$wrap = 0
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $text = GUICtrlRead($Edit1)
            Local $pos = ControlGetPos($Form2,'',$Edit1)
            If $wrap = 0 Then
                GUICtrlDelete($Edit1)
                $Edit1 = GUICtrlCreateEdit("", $pos[0], $pos[1], $pos[2], $pos[3],BitOR($ES_WANTRETURN,0x50300104))
                GUICtrlSetData($Edit1,$text)
                $wrap = 1
            Else
                GUICtrlDelete($Edit1)
                $Edit1 = GUICtrlCreateEdit("", $pos[0], $pos[1], $pos[2], $pos[3],BitOR($ES_WANTRETURN,0x50200104))
                GUICtrlSetData($Edit1,$text)
                $wrap = 0
            EndIf
    EndSwitch
WEnd
Edited by leomoon
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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