Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to determine TextBox width?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01425392
Message ID:
01425525
Vues:
43
Hi,

Good idea!

I will try this GETPEM and see how it determines the textbox width.

>>Hi,
>>
>>I have a TextBox control which is bound to a C32 field.
>>
>>How do I programatically find out the shortest width of the TextBox and make sure any 32 characters inputed will be displayed fully in the textbox?
>>
>>I was thinking:
>>TextBox.Width = 32 * FONTMETRIC(7, TextBox.FontName, TextBox.FontSize)
>>
>>But FONTMETRIC(7) is crazy... for Arial font size 10, it gives me 35 about 6 time of FONTMETRIC(6)...
>
>Hi Lim,
>
>What about you let foxpro calculate the size? Something like this (I let the label object stay just to check it,of course you should not show it, and you should also test parameters etc.) (and of course as you are removing the object you do not need the uniqueness of the name)
>
>
>local loForm
>loForm				= Newobject("myForm")
>loForm.Show(1)
>RETURN
>
>DEFINE CLASS myForm AS form
>
>
>	DoCreate = .T.
>	Name = "myForm"
>
>	ADD OBJECT textbox1 AS textbox WITH ;
>		Value = "This is a test", ;
>		Height = 23, ;
>		Left = 8, ;
>		Top = 27, ;
>		Width = 100, ;
>		Name = "textbox1"
>
>
>	ADD OBJECT textbox2 AS textbox WITH ;
>		Value = "This is a test", ;
>		Height = 23, ;
>		Left = 8, ;
>		Top = 51, ;
>		Width = 100, ;
>		Name = "textbox2"
>
>
>	ADD OBJECT textbox3 AS textbox WITH ;
>		Value = "This is a test", ;
>		Height = 23, ;
>		Left = 8, ;
>		Top = 75, ;
>		Width = 100, ;
>		Name = "textbox3"
>
>
>	ADD OBJECT textbox4 AS textbox WITH ;
>		Value = "This is a test", ;
>		Height = 23, ;
>		Left = 8, ;
>		Top = 99, ;
>		Width = 100, ;
>		Name = "textbox4"
>
>
>	ADD OBJECT textbox5 AS textbox WITH ;
>		Value = "This is a test", ;
>		Height = 23, ;
>		Left = 8, ;
>		Top = 123, ;
>		Width = 100, ;
>		Name = "textbox5"
>
>
>	ADD OBJECT textbox6 AS textbox WITH ;
>		Value = "This is a test", ;
>		Height = 23, ;
>		Left = 8, ;
>		Top = 147, ;
>		Width = 100, ;
>		Name = "textbox6"
>
>
>	ADD OBJECT textbox7 AS textbox WITH ;
>		Value = "This is a test", ;
>		Height = 23, ;
>		Left = 8, ;
>		Top = 171, ;
>		Width = 100, ;
>		Name = "textbox7", ;
>		BorderStyle = 0
>
>
>	ADD OBJECT textbox8 AS textbox WITH ;
>		Value = "This is a test", ;
>		Height = 23, ;
>		Left = 8, ;
>		Top = 195, ;
>		Width = 100, ;
>		Name = "textbox8"
>
>
>	PROCEDURE setTextboxWidth
>		lparameters toTextbox as TextBox
>
>		local loLabel as Label, lnWidth as Integer, llLockScreen as Boolean
>
>		thisform.AddObject('lblAux' + toTextbox.Name, 'Label')
>
>		llLockScreen			= thisform.LockScreen
>		thisform.LockScreen		= .t.
>		with Getpem(thisform, 'lblAux' + toTextbox.Name) as Label
>			.Top					= toTextBox.Top
>			.Left					= 200
>			.BorderStyle			= toTextbox.BorderStyle
>			.Visible				= .t.
>			.FontBold				= toTextbox.FontBold
>			.FontItalic				= toTextbox.FontItalic
>			.FontName				= toTextbox.FontName
>			.FontSize				= toTextbox.FontSize
>			.AutoSize				= .t.
>			.Caption				= toTextbox.Value
>			lnWidth					= .Width + toTextbox.Margin * 2 + Iif(toTextbox.BorderStyle = 0, 0, 4)
>		endwith
>		thisform.LockScreen		= llLockScreen
>
>		*thisform.RemoveObject('lblAux' + toTextbox.Name)
>
>		return lnWidth
>	ENDPROC
>
>
>	PROCEDURE Init
>		local lnTextbox, loTextbox, lnFonts, laFonts(1)
>
>
>		Rand(-1)
>		Afont(laFonts)
>		lnFonts				= Alen(laFonts)
>
>		for lnTextBox = 1 to 8
>			loTextbox			= Getpem(thisform, 'textbox' + Str(lnTextbox, 1))
>			loTextbox.FontName	= laFonts[Int(Rand() * lnFonts + 1)]
>			loTextbox.FontSize	= 10
>		next lnTextBox
>	ENDPROC
>
>
>	PROCEDURE textbox1.Refresh
>		this.Width		= thisform.setTextboxWidth(this)
>	ENDPROC
>
>
>	PROCEDURE textbox2.Refresh
>		this.Width		= thisform.setTextboxWidth(this)
>	ENDPROC
>
>
>	PROCEDURE textbox3.Refresh
>		this.Width		= thisform.setTextboxWidth(this)
>	ENDPROC
>
>
>	PROCEDURE textbox4.Refresh
>		this.Width		= thisform.setTextboxWidth(this)
>	ENDPROC
>
>
>	PROCEDURE textbox5.Refresh
>		this.Width		= thisform.setTextboxWidth(this)
>	ENDPROC
>
>
>	PROCEDURE textbox6.Refresh
>		this.Width		= thisform.setTextboxWidth(this)
>	ENDPROC
>
>
>	PROCEDURE textbox7.Refresh
>		this.Width		= thisform.setTextboxWidth(this)
>	ENDPROC
>
>
>	PROCEDURE textbox8.Refresh
>		this.Width		= thisform.setTextboxWidth(this)
>	ENDPROC
>
>
>ENDDEFINE
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform