Page 1 of 1
Width of a Get SOLVED
Posted: Tue Jun 16, 2020 10:44 pm
by FranciscoA
Hi.
How do I can adjust the width of oGet to the width of its text variable, at runtime?
¿Cómo puedo ajustar el ancho de oGet al ancho de su variable de texto, en tiempo de ejecución?
Thanks in advance.
Re: Width of a Get
Posted: Tue Jun 16, 2020 11:41 pm
by Cgallegoa
Francisco,
Code: Select all
#include "FiveWin.ch"
Function Inicio()
LOCAL oDlg, oGet1, cTxt1, oFont1
cTxt1 := "oGet width for any text"
DEFINE FONT oFont1 NAME "MS Sans Serif" SIZE 0,-10
DEFINE DIALOG oDlg FROM 0,0 TO 200,400 PIXEL
@ 20,10 GET oGet1 VAR cTxt1 OF oDlg SIZE 100,10 PIXEL FONT oFont1
ACTIVATE DIALOG oDlg CENTERED ON INIT AjustGet(oGet1)
Return(NIL)
Function AjustGet(oGet1)
LOCAL nWidthTxt := AllTrim(oGet1:cCaption)
oGet1:nWidth := GetTextWidth( 0, Alltrim(oGet1:cCaption), oGet1:oFont:hFont ) + 8 // 8 -> Valor ajuste.
oGet1:Refresh()
Return(NIL)
Re: Width of a Get
Posted: Wed Jun 17, 2020 12:04 am
by Cgallegoa
Francisco, a better version
Code: Select all
#include "FiveWin.ch"
Function Inicio()
LOCAL oDlg, oGet1, cTxt1, oFont1
cTxt1 := "oGet width for any text"
DEFINE FONT oFont1 NAME "MS Sans Serif" SIZE 0,-10
DEFINE DIALOG oDlg FROM 0,0 TO 200,400 PIXEL
@ 20,10 BUTTON "Probar varios anchos" OF oDlg PIXEL ACTION VariosAjustes(oGet1) SIZE 70,20
@ 50,20 GET oGet1 VAR cTxt1 OF oDlg SIZE 100,10 PIXEL FONT oFont1
ACTIVATE DIALOG oDlg CENTERED ON INIT AjustGet(oGet1)
Return(NIL)
Function AjustGet(oGet1)
LOCAL nWidthTxt := AllTrim(oGet1:cCaption), i := 1
oGet1:nWidth := GetTextWidth( 0, Alltrim(oGet1:cText), oGet1:oFont:hFont ) + 8 // 8 -> Valor ajuste.
oGet1:Refresh()
Return(NIL)
Function VariosAjustes(oGet1)
LOCAL cTxt
LOCAL nWidthTxt := AllTrim(oGet1:cCaption), i := 1
LOCAL aTextos := {"Texto 1",;
"Un texto más largo",;
"Menos texto",;
"Otra línea pero más larga",;
"Mucha más largo que todas las líneas anteriores",;
"Otra vez corto"}
For i :=1 TO Len(aTextos)
cTxt := AllTrim(aTextos[i])
oGet1:cText := cTxt
oGet1:nWidth := GetTextWidth( 0, cTxt, oGet1:oFont:hFont ) + 8 // 8 -> Valor ajuste.
oGet1:Refresh()
SysWait(2)
next
Return(NIL)
Re: Width of a Get
Posted: Wed Jun 17, 2020 1:51 pm
by FranciscoA
Carlos,
Works fine!
Thanks