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

Seleccionar todo el texto en un TextBox

Post by arroya2 »

Español:
Hola.
Lo que necesito básicamente es que el usuario, en algunos formularios, tenga valores predeterminados, pero si estos no son los que necesita, simplemente con teclear el nuevo valor, se borra el valor predeterminado.
Gracias

English:
Hello.
What I need is basically a user, in some forms, have defaults, but if these are not needed, simply by typing the new value, clears the default.
Thanks
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:Español:
Hola.
Lo que necesito básicamente es que el usuario, en algunos formularios, tenga valores predeterminados, pero si estos no son los que necesita, simplemente con teclear el nuevo valor, se borra el valor predeterminado.
Gracias

English:
Hello.
What I need is basically a user, in some forms, have defaults, but if these are not needed, simply by typing the new value, clears the default.
Thanks
The following code let you select text in a TextBox.

You need to provide:

cControlName
cParentForm
nFirstCharacter
nLastCharacter

Additionaly you must define the following constant:

#define EM_SETSEL 177

Code: Select all


SendMessage( GetControlHandle(cControlName , cParentForm )  , EM_SETSEL , nFirstCharacter , nLastCharacter )

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
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 »

Thanks a lot Roberto.

Can anybody imagine to call a C API function in a single line?

I wonder it is possible from HMG alone. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
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:Español:
Hola.
Lo que necesito básicamente es que el usuario, en algunos formularios, tenga valores predeterminados, pero si estos no son los que necesita, simplemente con teclear el nuevo valor, se borra el valor predeterminado.
Gracias

English:
Hello.
What I need is basically a user, in some forms, have defaults, but if these are not needed, simply by typing the new value, clears the default.
Thanks
The following code let you select text in a TextBox.

You need to provide:

cControlName
cParentForm
nFirstCharacter
nLastCharacter

Additionaly you must define the following constant:

#define EM_SETSEL 177

Code: Select all


SendMessage( GetControlHandle(cControlName , cParentForm )  , EM_SETSEL , nFirstCharacter , nLastCharacter )

Regards,

Roberto.
Gracias Roberto.
Lo que me indica no me suena nada. Le indico que soy principiante. Si me puede indicar donde puedo encontrar un ejemplo que ilustre su información o si me puede ilustrar con un ejemplo, se lo agradeceré.
Muchas gracias. Rafael Pérez
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 »

Roberto Lopez wrote:
Additionaly you must define the following constant:

#define EM_SETSEL 177

Code: Select all


SendMessage( GetControlHandle(cControlName , cParentForm )  , EM_SETSEL , nFirstCharacter , nLastCharacter )

Regards,

Roberto.
I'm wondering, how to select whole numeric textbox when I enter in this field by mouse?
I've tried to put this code in OnGotFocus exception, but it doesn't work :(
arroya2
Posts: 172
Joined: Thu Aug 06, 2009 7:16 am

Re: Seleccionar todo el texto en un TextBox

Post by arroya2 »

Hola.
He observado que en el modo edición, cuando se cambia de un campo a otro con la tecla TAB, en el campo siguiente queda seleccionado todo el contenido.

Pero cuando se edita, en el primer campo de la edición no se selecciona nada del contenido de ese campo. ¿Porqué? ¿Cómo se puede resolver esto para que el contenido de ese primer campo también quede seleccionado?

Saludos
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 wanna get effect of selection of whole field - getting focus of him by a mouse. Of course it works if I'm navigating with TAB.

I don't know, how to select all characters in any field during initialisation of window.
User avatar
gfilatov
Posts: 1067
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Seleccionar todo el texto en un TextBox

Post by gfilatov »

mol wrote:...
I don't know, how to select all characters in any field during initialisation of window.
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:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
arroya2
Posts: 172
Joined: Thu Aug 06, 2009 7:16 am

Re: Seleccionar todo el texto en un TextBox

Post by arroya2 »

Hola Grigory.
Me podrías indicar donde están documentadas las funciones:
- Setfocus()
- GetControlHandle()
- SendMessage()

Gracias y Saludos
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 Grigory.
Me podrías indicar donde están documentadas las funciones:
- Setfocus()
- GetControlHandle()
- SendMessage()

Gracias y Saludos
Rafael Pérez
These are Windows API functions used internally by HMG.

You can found information about that in MSDN.

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
Post Reply