Page 1 of 1

Label : texto centrado verticalmente

Posted: Sun Mar 29, 2026 2:31 pm
by edufloriv
Saludos amigos,

¿ Alguien sabe si se puede alinear el texto en el centro VERTICALMENTE de los controles Label ?. Cuando le pongo una altura de 30 (HEIGTH 30) el texto se ve ligeramente ubicado hacia arriba, dejando más espacio abajo. Agradeceré cualquier ayuda al respecto. Saludos.

--------------------------------------------------------------------------------------------------------

Hi friends,

Does anyone know if it's possible to center the text in Label controls vertically? When I set the height to 30, the text appears slightly raised, leaving more space at the bottom. Any help would be greatly appreciated. Thanks.

Re: Label : texto centrado verticalmente

Posted: Sun Mar 29, 2026 6:47 pm
by danielmaximiliano
Hola Edu : no entiendo bien pero puedes probar
DEFINE LABEL <ControlName>

PARENT <ParentWindowName>

ROW <nValue>

COL <nValue>

VALUE <cValue>

ONCLICK <ActionProcedureName>

WIDTH <nWidth>

HEIGHT <nHeight>

AUTOSIZE <lValue> .T. por si cambias de tipo de letra en runtime

FONTNAME <cValue>

FONTSIZE <nValue>

ALIGNMENT Left | Right | Center

END LABEL
pero si redimensionas la ventana

Code: Select all

FUNCTION ReCenter()
   WITH OBJECT Form_1.Label_1
      .COL := ( Form_1.WIDTH - .WIDTH ) / 2
      .ROW := ( Form_1.HEIGHT - .HEIGHT ) / 2
   END WITH
RETURN NIL

Re: Label : texto centrado verticalmente

Posted: Mon Mar 30, 2026 6:59 am
by serge_girard
Daniel,

This gives me syntax error....

Serge

Re: Label : texto centrado verticalmente

Posted: Mon Mar 30, 2026 5:04 pm
by danielmaximiliano
serge_girard wrote: Mon Mar 30, 2026 6:59 am Daniel,

This gives me syntax error....

Serge
perdon el error ocurre porque no es un objeto

Code: Select all

#include "hmg.ch"

FUNCTION Main

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 600 ;
      HEIGHT 400 ;
      TITLE 'Label centrado con padding dentro de Frame' ;
      MAIN ;
      ON SIZE CenterLabelInFrame()

      DEFINE FRAME Frame_1
         ROW 60
         COL 80
         WIDTH 440
         HEIGHT 200
         CAPTION "Frame con padding"
      END FRAME

      DEFINE LABEL Label_1
         VALUE "Texto centrado con margen interno"
         AUTOSIZE .T.
      END LABEL

      DEFINE BUTTON Btn_1
         ROW 300
         COL 200
         WIDTH 200
         HEIGHT 30
         CAPTION "Cambiar texto"
         ACTION ChangeText()
      END BUTTON

   END WINDOW

   CENTER WINDOW Form_1
   ACTIVATE WINDOW Form_1

   CenterLabelInFrame()

RETURN NIL


 FUNCTION CenterLabelInFrame()

   LOCAL nPadTop    := 25
   LOCAL nPadBottom := 10
   LOCAL nPadLeft   := 10
   LOCAL nPadRight  := 10

   LOCAL nInnerWidth  := Form_1.Frame_1.WIDTH  - nPadLeft - nPadRight
   LOCAL nInnerHeight := Form_1.Frame_1.HEIGHT - nPadTop  - nPadBottom

   Form_1.Label_1.COL := Form_1.Frame_1.COL + nPadLeft + ;
                         ( nInnerWidth - Form_1.Label_1.WIDTH ) / 2

   Form_1.Label_1.ROW := Form_1.Frame_1.ROW + nPadTop + ;
                         ( nInnerHeight - Form_1.Label_1.HEIGHT ) / 2



RETURN NIL
FUNCTION ChangeText()

   Form_1.Label_1.VALUE := ;
      "Texto más largo centrado respetando padding del frame"

   //Form_1.Label_1.AUTOSIZE := .T.

   CenterLabelInFrame()

RETURN NIL

Re: Label : texto centrado verticalmente

Posted: Mon Mar 30, 2026 6:01 pm
by serge_girard
Thanks DaNiElMaXiMiLiAnO !

Re: Label : texto centrado verticalmente

Posted: Sat Apr 04, 2026 2:31 pm
by edufloriv
Daniel muchas gracias,

Aún no he tenido tiempo pero lo probaré. Saludos cordiales.

Re: Label : texto centrado verticalmente

Posted: Tue Apr 07, 2026 10:33 am
by mol
You can center vertical LABEL control only if it has one line of text - try
HMG_ChangeWindowStyle(GetControlHandle("Label_1","Form_1"), 0x00000200 /*SS_CENTERIMAGE*/, NIL, .F., .T.)

you can also write
HMG_ChangeWindowStyle(Form_1.Label_1.Handle, 0x00000200 /*SS_CENTERIMAGE*/, NIL, .F., .T.)

Remember! It works only for one line labels!

Re: Label : texto centrado verticalmente

Posted: Wed Apr 08, 2026 4:36 pm
by franco
This may help. Not sure if this is what you are asking.

Code: Select all

#include "hmg.ch"

Function Main


	DEFINE WINDOW Form_Main ;
		AT 0,0 ;
		WIDTH 640 HEIGHT 480 ;
		TITLE 'Main Window' ;
		MAIN 

		@ 50,50 LABEL Label_1 ;                            
		WIDTH 500 HEIGHT 200 ;         
		VALUE "Click ME! "+ CRLF+ ;
				"I am testing for hmg." + CRLF+  ;
				"Seem to Work." ;
		ACTION MsgInfo('Label Clicked!!!') ;
		FONT 'Areal'   SIZE 24  CENTERALIGN ;
		tooltip 'Help Me'

		@ 260,10 LABEL Label_2 ;
		AUTOSIZE ;
		VALUE '...' ;
		ACTION {||{msgbox(this.name)}, {  ,msginfo('test')}}

	END WINDOW

	Form_Main.Label_2.Value := 'Hello All, This Is An AutoSIzable Label!!!'

	CENTER WINDOW Form_Main

	ACTIVATE WINDOW Form_Main

Return 

Re: Label : texto centrado verticalmente

Posted: Fri Apr 10, 2026 3:53 pm
by franco
This also works for column.

Code: Select all

		@ 50,50 LABEL Label_1 ;                       
		WIDTH 500 HEIGHT 200 ;         
		VALUE "Click  "+ CRLF+ ;
			  "Me!" + CRLF+  ;
		     	  "Seems" + CRLF+ ;
			  "To "+ CRLF+ ;
			  " Work" ;
		ACTION MsgInfo('Label Clicked!!!') ;
		FONT 'Areal'   SIZE 24  CENTERALIGN ;
		tooltip 'Help Me'