Width of a Get SOLVED

Width of a Get SOLVED

Postby FranciscoA » Tue Jun 16, 2020 10:44 pm

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.

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

Re: Width of a Get

Postby Cgallegoa » Tue Jun 16, 2020 11:41 pm

Francisco,

Code: Select all  Expand view  RUN
#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-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Cgallegoa
 
Posts: 494
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: Width of a Get

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

Francisco, a better version :D

Code: Select all  Expand view  RUN
#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-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Cgallegoa
 
Posts: 494
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: Width of a Get

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

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

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 55 guests