Ajustar ancho de un Get SOLUCIONADO

Ajustar ancho de un Get SOLUCIONADO

Postby FranciscoA » 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.
Last edited by FranciscoA on Wed Jun 17, 2020 1:49 pm, edited 1 time in total.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2110
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Ajustar ancho de un Get

Postby Cgallegoa » Wed Jun 17, 2020 12:00 am

Francisco,

Code: Select all  Expand view
#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-23.10, xHarbour 1.2.3 Build 20190603, Borland C++7.30, PellesC ***
Cgallegoa
 
Posts: 414
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: Ajustar ancho de un Get

Postby Cgallegoa » Wed Jun 17, 2020 12:01 am

Francisco, versión mejorada :D

Code: Select all  Expand view
#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-23.10, xHarbour 1.2.3 Build 20190603, Borland C++7.30, PellesC ***
Cgallegoa
 
Posts: 414
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: Ajustar ancho de un Get

Postby FranciscoA » Wed Jun 17, 2020 1:48 pm

Carlos,
Funciona bien. Excelente ejemplo!
Muchas gracias.
Saludos.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2110
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 77 guests