Fenzik Posted May 20, 2022 Share Posted May 20, 2022 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 More sharing options...
pixelsearch Posted May 20, 2022 Share Posted May 20, 2022 Hi Fenzik, Just add style 0x00008000 in your BitOr() when creating the richedit control. Now everybody's searching what style is it Link to comment Share on other sites More sharing options...
Fenzik Posted May 20, 2022 Author Share Posted May 20, 2022 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 More sharing options...
pixelsearch Posted May 20, 2022 Share Posted May 20, 2022 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 More sharing options...
Fenzik Posted May 20, 2022 Author Share Posted May 20, 2022 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 More sharing options...
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