Jump to content

Autoselecting text in Richedit control when focussed by Tab Key


 Share

Recommended Posts

Hello all,

i have following question.

Is it possible to prevent the Richedit control from autoselecting text when control is focussed by Tab key?

You can see this behaviour in this modified example from Help file.

When you press the Tab Key and cycle through the elements, when Richedit is focussed, the text is every time selected.

Is there some way to prevent this, so the selection remains untouched when i focus the Richedit?

Thank you.

Fenzik

 

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
        Local $hGui, $hRichEdit, $iMsg
        $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 400, -1, -1)
        $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
                        BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
        _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "This is more text")
        $btn = guictrlcreatebutton("BTN", 10, 330, 50, 20)
        GUISetState(@SW_SHOW)

        While True
                $iMsg = GUIGetMsg()
                Select
                        Case $iMsg = $GUI_EVENT_CLOSE
                                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                                ; GUIDelete()   ; is OK too
                                Exit
                EndSelect
        WEnd
EndFunc   ;==>Example

 

Link to comment
Share on other sites

Hello pixelsearch,

it works like a magic.. :)

I do'nt why and how, but it works.

Can you describe the style, hope not only for me? :)

Thank you so much for the easy and effective solution!

Link to comment
Share on other sites

21 minutes ago, Fenzik said:

Can you describe the style, hope not only for me? :)

Sure !
It corresponds to style $ES_SAVESEL (not sure it's in AutoIt help file but I may be wrong)
Infos on MSDN page :

ES_SAVESEL : Preserves the selection when the control loses the focus.
By default, the entire contents of the control are selected when it regains the focus.

I indicated its "not really useful" value 0x00008000 just for fun, as found in the 2nd spoiler in this post.

Link to comment
Share on other sites

Thank you.

So i think that it's useful for example for accessibility reasons, because when you have for example some read only Richedit with some text, you don't want to have it selectet when you use the keyboard to navigate the focus.

The second relatively related sideeffect is the difference between _GUICtrlRichEdit_SetText and _GUICtrlRichEdit_StreamFromVar functions, where _GUICtrlRichEdit_StreamFromVar function put the cursor to the last character of the text and _GUICtrlRichEdit_SetText function puts it on the first character.

Thank you again!

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...