Width of a Get SOLVED

Post Reply
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Width of a Get SOLVED

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

Fwxh1204-MySql-TMySql
Cgallegoa
Posts: 335
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador
Contact:

Re: Width of a Get

Post 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)
 
Saludos,

Carlos Gallego

*** FWH-20.07, xHarbour 1.2.3 Build 20190603, Borland C++7.30, PellesC ***
Cgallegoa
Posts: 335
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador
Contact:

Re: Width of a Get

Post by Cgallegoa »

Francisco, a better version :D

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)
 
Saludos,

Carlos Gallego

*** FWH-20.07, xHarbour 1.2.3 Build 20190603, Borland C++7.30, PellesC ***
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Width of a Get

Post by FranciscoA »

Carlos,
Works fine!
Thanks
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh1204-MySql-TMySql
Post Reply