Page 1 of 1

marked String in TEXTBOX when using Mouse ?

Posted: Tue Aug 10, 2021 2:34 am
by AUGE_OHR
hi,

when i use TAB-Key ( CHR(9) ) a String in Textbox show "marked"
when i click into TEXTBOX nothing is "marked"

i try GOTFOCUS and

Code: Select all

   hWndEdit := GetControlHandle( ControlName, ParentForm )
   SendMessage(hWndEdit, EM_SETSEL, nStartIndex, nEndIndex)
where

Code: Select all

   nStartIndex := 0
   nEndIndex := LEN(String)  // nEndIndex := -1 ALL
Cursor Caret Position is right at nEndIndex
but i "see" no "mark" in TEXTBOX ... :(

it does work in EDITBOX :!:

so what i´m doing wrong under HMG :idea:

Re: marked String in TEXTBOX when using Mouse ?

Posted: Tue Aug 10, 2021 10:11 am
by mol
try to use:

Code: Select all

SetProperty(ParentForm, ControlName, "CaretPos", nEndIndex )
Edit:
Sorry, I misunderstood your request... I can't delete my post. I don't know how to select whole text

Edit:

Try:

Code: Select all

DoMethod(ParentForm, ControlName, "SetFocus")
after clicking mouse

Re: marked String in TEXTBOX when using Mouse ?

Posted: Wed Aug 11, 2021 12:57 am
by AUGE_OHR
hi,

sorry i have descript it wrong :

when using TAB Key it will "mark" all when get into TEXTBOX -> GOTFOCUS
when "click" into a TEXTBOX it will not show "mark" :o

also when Field was empty TEXTBOX is not "marked"
so i try to use EM_SETSEL with ONGOTFOCUS which should react when "click" into TEXTBOX

but it seems not to work "on click" :( ( except empty TEXTBOX )

Code: Select all

DEFINE TEXTBOX Text_001+
   ONGOTFOCUS MarkText(ThisWindow.Name, This.Name )
   ONLOSTFOCUS DeHilite(ThisWindow.Name, This.Name )

Code: Select all

PROCEDURE MarkText( ParentForm, ControlName )
LOCAL cValue, hWndEdit, nStartIndex := 0, nEndIndex := - 1

   IF _IsControlDefined( ControlName, ParentForm )
      DoMethod(ParentForm, ControlName, "SetFocus") // add try Mol
      SetProperty(ParentForm, ControlName, "CaretPos", nEndIndex ) // add try Mol

      cValue := GetProperty( ParentForm, ControlName, "Value" )
      IF EMPTY( cValue )
         SetProperty(ParentForm,ControlName,"BackColor",SP_nColor11() )
         SetProperty(ParentForm,ControlName,"FontColor",SP_nColor12() )
      ELSE
         IF VALTYPE(cValue) <> "C"
            cValue := hb_valToExp(cValue)
         ENDIF
         nEndIndex := LEN(TRIM(cValue))

         hWndEdit := GetControlHandle( ControlName, ParentForm )
         SendMessage(hWndEdit, EM_SETSEL, nStartIndex, nEndIndex)
      ENDIF
   ENDIF
RETURN

Code: Select all

PROCEDURE DeHilite( ParentForm, ControlName )
   IF _IsControlDefined( ControlName, ParentForm )
      SetProperty(ParentForm,ControlName,"BackColor",SP_nColor5() )
      SetProperty(ParentForm,ControlName,"FontColor",SP_nColor6() )
   ENDIF
RETURN

Re: marked String in TEXTBOX when using Mouse ?

Posted: Wed Aug 11, 2021 2:13 am
by srvet_claudio
Hi,
When you have a selected text, the cursor is positioned at the end of the selection. When you click into the textbox, you automatically move the cursor to the place of the click and then the selection is deleted because the click makes nStartIndex = nEndIndex

Re: marked String in TEXTBOX when using Mouse ?

Posted: Wed Aug 11, 2021 5:55 am
by AUGE_OHR
hi,
srvet_claudio wrote: Wed Aug 11, 2021 2:13 am nStartIndex = nEndIndex
aaah ... that make Sense. :idea:

thx for Advice