Seleccionar todo el texto en un TextBox

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

arroya2
Posts: 172
Joined: Thu Aug 06, 2009 7:16 am

Re: Seleccionar todo el texto en un TextBox

Post by arroya2 »

Muchas gracias Maestro Roberto.

Rafael Pérez
arroya2
Posts: 172
Joined: Thu Aug 06, 2009 7:16 am

Re: Seleccionar todo el texto en un TextBox

Post by arroya2 »

Hola Roberto.

Lamento tener que darte tanto la lata, pero es que he buscado las API de Windows y son muchísimas.

Me gustaría saber cuales son las que usa internamente HMG aparte de las tres que me has indicado.

Muy agradecido
Rafael Pérez
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Seleccionar todo el texto en un TextBox

Post by Roberto Lopez »

arroya2 wrote:Hola Roberto.

Lamento tener que darte tanto la lata, pero es que he buscado las API de Windows y son muchísimas.

Me gustaría saber cuales son las que usa internamente HMG aparte de las tres que me has indicado.

Muy agradecido
Rafael Pérez
HMG uses LOTS of WInAPi functions.

You should look at sources.

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
arroya2
Posts: 172
Joined: Thu Aug 06, 2009 7:16 am

Re: Seleccionar todo el texto en un TextBox

Post by arroya2 »

Roberto Lopez wrote:
arroya2 wrote:Hola Roberto.

Lamento tener que darte tanto la lata, pero es que he buscado las API de Windows y son muchísimas.

Me gustaría saber cuales son las que usa internamente HMG aparte de las tres que me has indicado.

Muy agradecido
Rafael Pérez
HMG uses LOTS of WInAPi functions.

You should look at sources.

Regards,

Roberto.
Supongo que se refiere a las fuentes de HMG. ¿De dónde me las puedo bajar?

Muchas gracias y saludos.
Rafael Pérez
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Seleccionar todo el texto en un TextBox

Post by Rathinagiri »

You can see them from c:\hmg\source\*.c
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Seleccionar todo el texto en un TextBox

Post by mol »

gfilatov wrote: Hello Mol,

Take a look for the following sample:

Code: Select all

#include "minigui.ch"

Function Main

DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 640 HEIGHT 480 ;
TITLE 'Test' ;
MAIN ;
ON INIT OnInit( 'Text_2' , 'Form_1' )

@ 50,10 TEXTBOX Text_1 ;
VALUE 123 ;
FONT 'Verdana' SIZE 12 ;
TOOLTIP 'Numeric TextBox' ;
NUMERIC ;
MAXLENGTH 5

@ 100,10 TEXTBOX Text_2 ;
VALUE "123" ;
FONT 'Verdana' SIZE 12 ;
TOOLTIP 'Character TextBox'

@ 150,20 Button Button_1 ;
Caption "Disable" ;
Height 80 ;
Action DisableControls()


@ 150,120 Button Button_2 ;
Caption "Enable" ;
Height 80 ;
Action EnableControls()

END WINDOW
Form_1.Center
Form_1.Activate
Return Nil

Function DisableControls()
Form_1.Text_1.Enabled := .F.
Form_1.Text_2.Enabled := .F.

Return Nil

Function EnableControls()
Form_1.Text_1.Enabled := .T.
Form_1.Text_2.Enabled := .T.

Return Nil

#define EM_SETSEL 177
Function OnInit( cControlName , cParentForm )
Setfocus( GetControlHandle( cControlName , cParentForm ) )
SendMessage( GetControlHandle( cControlName , cParentForm ) , EM_SETSEL , 0 , -1 ) 

Return Nil
:idea:
I've returnd to this Idea, but, as I observed, this SendMessage causes selection only from mouse cursor to end of the field.
Could anybody test it?
Marek
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Seleccionar todo el texto en un TextBox

Post by mol »

I want to refresh this topic because this solution doesn't work with mouse.
Somebody has any idea how to select whole field after enter by mouse?
User avatar
AUGE_OHR
Posts: 2061
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Seleccionar todo el texto en un TextBox

Post by AUGE_OHR »

hi Mol,

Code does work

Code: Select all

   hWndEdit := GetControlHandle( ControlName, ParentForm )
   SendMessage( hWndEdit, EM_SETSEL, nStartIndex, nEndIndex )
   // add this for Test
   DO EVENTS
   hb_idleSleep( 1.0 )
but "something" does delete my Color after "Sleep" when using Mouse ... hm
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2061
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Seleccionar todo el texto en un TextBox

Post by AUGE_OHR »

hi,

try this with TEXTBOX

Code: Select all

ONGOTFOCUS MarkText( ThisWindow.Name, This.Name )
ONLOSTFOCUS DeHilite( ThisWindow.Name, This.Name )

Code: Select all

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

   IF _IsControlDefined( ControlName, ParentForm )
      DoMethod( ParentForm, ControlName, "SetFocus" )
      SetProperty( ParentForm, ControlName, "CaretPos", nEndIndex )

      SetProperty( ParentForm, ControlName, "BackColor", SP_nColor11() )
      SetProperty( ParentForm, ControlName, "FontColor", SP_nColor12() )

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

Code: Select all

STATIC PROCEDURE DeHilite( ParentForm, ControlName )
   IF _IsControlDefined( ControlName, ParentForm )
      SetProperty( ParentForm, ControlName, "BackColor", SP_nColor5() )
      SetProperty( ParentForm, ControlName, "FontColor", SP_nColor6() )
   ENDIF
RETURN
it will "high-light" hole TEXTBOX but Cursor is at End of Entry

! Note : you must change Code to use "your" Color(s)
have fun
Jimmy
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: Seleccionar todo el texto en un TextBox

Post by Claudio Ricardo »

Hola Rafael, En los textbox yo pongo el valor predeterminado en la propiedad ' Value ' al crear el control
o después con SetProperty ("Form_Name" , "Text_Name" , "Value" , "Valor predeterminado")
Cuando el usuario accede a ese textbox con la tecla Tab se resalta (highlight) y cualquier tecla alfanumérica
que presione borra el valor predeterminado por mi y lo reemplaza por lo que está escribiendo.
Por ejemplo: para editar un artículo cargo todos los textbox de la ventana de editar artículo con los
valores actuales y el usuario sólo cambia el que necesita, luego se leen todos los textbox y se actualiza
la base de datos.
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
Post Reply