Jump to content

Recommended Posts

Posted

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

 

Posted

Hi Fenzik,

Just add style 0x00008000 in your BitOr() when creating the richedit control.
Now everybody's searching what style is it :D

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted

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!

Posted
  On 5/20/2022 at 10:23 AM, Fenzik said:

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

Expand  

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.

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted

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!

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