marked String in TEXTBOX when using Mouse ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

marked String in TEXTBOX when using Mouse ?

Post 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:
have fun
Jimmy
User avatar
mol
Posts: 3723
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: marked String in TEXTBOX when using Mouse ?

Post 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
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: marked String in TEXTBOX when using Mouse ?

Post 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
have fun
Jimmy
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: marked String in TEXTBOX when using Mouse ?

Post 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
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: marked String in TEXTBOX when using Mouse ?

Post by AUGE_OHR »

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

thx for Advice
have fun
Jimmy
Post Reply