FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Ajustar ancho de un Get SOLUCIONADO
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Ajustar ancho de un Get SOLUCIONADO
Posted: Tue Jun 16, 2020 10:46 PM

Hola a todos.
¿Cómo puedo ajustar el ancho de oGet al ancho de su variable de texto, en tiempo de ejecución?
Gracias por adelantado.

Hi.
How do I can adjust the width of oGet to the width of its text variable, at runtime?
Thanks in advance.

Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 514
Joined: Sun Oct 16, 2005 03:32 AM
Re: Ajustar ancho de un Get
Posted: Wed Jun 17, 2020 12:00 AM
Francisco,

Code (fw): Select all Collapse
#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)

Saludos,



Carlos Gallego



*** FWH-25.12, xHarbour 1.3.1 Build 20241008, Borland C++7.70, PellesC, ADS 11.1***

Posts: 514
Joined: Sun Oct 16, 2005 03:32 AM
Re: Ajustar ancho de un Get
Posted: Wed Jun 17, 2020 12:01 AM
Francisco, versión mejorada :-)

Code (fw): Select all Collapse
#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)

Saludos,



Carlos Gallego



*** FWH-25.12, xHarbour 1.3.1 Build 20241008, Borland C++7.70, PellesC, ADS 11.1***

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: Ajustar ancho de un Get
Posted: Wed Jun 17, 2020 01:48 PM

Carlos,
Funciona bien. Excelente ejemplo!
Muchas gracias.
Saludos.

Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql

Continue the discussion