Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating an autosizing editbox
Message
De
23/03/2005 12:25:58
 
 
À
22/03/2005 12:02:05
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00998157
Message ID:
00998516
Vues:
34
>VFP 8, 9: I've been trying to create an autosizing editbox - in other words an editbox that adjusts its height so that it shows the full contents of its Value without the need for a scrollbar and without showing any unnecessary blank lines. The reason I'm looking for an autosizing editbox (and not a label) is that I have text to display that may be longer than the 254 char limit of a label's caption. I also want the user to be able to highlight text within this control for copy to the clipboard.
>
>I've tried 3 approaches to calculate the vertical space required to display a wordwrapped line of text:
>
>- Win32 API DrawText()/CreateFont()
>
>- VFP's old "?" output command in conjunction with fontmetric() and row()
>
>- Manually parsing the text to be displayed and using fontmetric(), textwidth() to calculate word/line breaks and manually calculating text height
>
>All 3 of the above techniques produce IDENTICAL text height results. Unfortunately, the VFP editbox uses a "mysterious" word wrapping algorithm that wraps text slightly differently than the above techniques.
>
>So, is there anyway using the native VFP editbox that I can determine how many lines it needs to fully display a block of text without using scrollbars? Or is there some property I can set that will make the editbox wrap text consistent with one of the above techniques for calculating text height?
>
>Thank you,
>
>Malcolm

You can joy with this:
PUBLIC oform1

#DEFINE _FONTNAME "Arial" &&"Courier New"
#DEFINE _FONTSIZE 8

oform1=NEWOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form

	Autocenter = .T.
	Caption = "Form1"
	FontName = _FONTNAME 
	FontSize = _FONTSIZE 

	ADD OBJECT edit1 AS AutoSizeEditBox  WITH ;
		FontName = _FONTNAME , ;
		FontSize = _FONTSIZE , ;
		BorderStyle = 1, ;
		Height = 42, ;
		Left = 11, ;
		Margin = 1, ;
		ScrollBars = 0, ;
		Top = 43, ;
		Width = 103, ;
		BackColor = RGB(198,241,255), ;
		IntegralHeight = .F.,;
		Themes = .T.,;
		SpecialEffect = 0

	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 8, ;
		Left = 36, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "AUTOSIZE"

ENDDEFINE

DEFINE CLASS AutoSizeEditBox AS EditBox

	PROCEDURE Gotfocus
		This.ResizeToText(.T.)
	ENDPROC

	PROCEDURE InteractiveChange
		This.ResizeToText(.T.)
	ENDPROC

	PROCEDURE Lostfocus
		This.ResizeToText
	ENDPROC

	PROCEDURE ResizeToText(forediting)
		* this autosized the EditBox
		PRIVATE frameSize,text
		STORE (m.this.Margin+m.this.BorderStyle+IIF(EMPTY(m.this.SpecialEffect),2,1))*2 TO frameSize
		STORE IIF(m.forediting,m.THIS.Text+[ ]+0h0A,M.THIS.Text) TO text
		RETURN THIS.MOVE(m.this.left,m.this.top,m.frameSize+THISFORM.TEXTWIDTH(m.text),m.frameSize+THISFORM.TEXTHEIGHT(m.text))
	
ENDDEFINE
Fabio
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform