>Hi there,
>
>in a program I build dynamically a container filled with labels which contain Field-descriptions and values, somezjing like;
>
>Author: Some Author
>Tztle : Some Title
>
>I use labels set to a given width which is calculated during runtime amd autosize = .T. This works fine with wordwrapping
>but unfortunately the maximum size of the caption-property is 255 chars and some values are bigger. The edit-box has no autosize-property so I don not know how to handle this. Can someone give me some help how to handle this?
>
>Thanks in advance
>
>Thomas
This function will calculate the required height for an EditBox to hold a text completely. The other font settings that may affect the rendering of text (and, hence, the height of the control) were left behind, but can be also included in the function logic.
LOCAL Description AS String
TEXT TO m.Description NOSHOW
Did the mothers really die? Three centuries of maternal mortality in the world we have lost
ENDTEXT
_Screen.AddObject("Test", "EditBox")
_Screen.Test.Width = 200
_Screen.Test.ScrollBars = 0
_Screen.Test.Height = NeededHeightForAnEditBox(m.Description,200)
_Screen.Test.Value = m.Description
_Screen.Test.Visible = .T.
WAIT WINDOW "Click to continue"
_Screen.RemoveObject("Test")
_Screen.AddObject("Test", "EditBox")
_Screen.Test.Width = 200
_Screen.Test.ScrollBars = 0
_Screen.Test.FontSize = 12
_Screen.Test.FontItalic = .T.
_Screen.Test.Margin = 4
_Screen.Test.Height = NeededHeightForAnEditBox(m.Description,200,_Screen.Test)
_Screen.Test.Value = m.Description
_Screen.Test.Visible = .T.
WAIT WINDOW "Click to continue"
_Screen.RemoveObject("Test")
FUNCTION NeededHeightForAnEditBox (Contents AS String, AvailableWidth AS Integer, Model)
LOCAL NeededHeightForAnEditBox AS Integer
LOCAL TestBox AS EditBox
IF PCOUNT() = 3
IF TYPE("m.Model") == "C"
m.TestBox = CREATEOBJECT(m.Model)
ELSE
m.TestBox = CREATEOBJECT("EditBox")
WITH m.Model AS EditBox
m.TestBox.FontName = .FontName
m.TestBox.FontSize = .FontSize
m.TestBox.FontItalic = .FontItalic
m.TestBox.FontBold = .FontBold
m.TestBox.Margin = .Margin
m.TestBox.BorderStyle = .BorderStyle
ENDWITH
ENDIF
ELSE
m.TestBox = CREATEOBJECT("EditBox")
ENDIF
LOCAL LineHeight AS Integer
LOCAL ExtraHeight AS Integer
LOCAL FontStyle AS String
m.FontStyle = EVL(;
IIF(m.TestBox.FontBold,"B","") + ;
IIF(m.TestBox.FontItalic,"I",""),"N")
m.TestBox.IntegralHeight = .F.
m.TestBox.ScrollBars = 0
m.TestBox.Height = 0
m.ExtraHeight = m.TestBox.Height
m.TestBox.IntegralHeight = .T.
m.LineHeight = m.TestBox.Height + FONTMETRIC(4,m.TestBox.FontName,m.TestBox.FontSize,m.FontStyle) - m.ExtraHeight
LOCAL ARRAY Words(1)
LOCAL WordIndex AS Integer
LOCAL WordWidth AS Integer
LOCAL SpaceWidth AS Integer
LOCAL OcuppiedInLine AS Integer
LOCAL LinesNeeded AS Integer
m.LinesNeeded = 1
m.OcuppiedInLine = 0
m.SpaceWidth = TXTWIDTH(" ",m.TestBox.FontName,m.TestBox.FontSize,m.FontStyle) * FONTMETRIC(6,m.TestBox.FontName,m.TestBox.FontSize,m.FontStyle)
FOR m.WordIndex = 1 TO ALINES(m.Words,m.Contents,1 + 4," ")
m.WordWidth = TXTWIDTH(m.Words[m.WordIndex],m.TestBox.FontName,m.TestBox.FontSize,m.FontStyle) * FONTMETRIC(6,m.TestBox.FontName,m.TestBox.FontSize,m.FontStyle)
m.OcuppiedInLine = m.OcuppiedInLine + m.WordWidth
DO CASE
CASE m.OcuppiedInLine > m.AvailableWidth
m.OcuppiedInLine = m.WordWidth
m.LinesNeeded = m.LinesNeeded + 1
CASE m.OcuppiedInLine = m.AvailableWidth
IF m.WordIndex < ALEN(m.Words)
m.OcuppiedInLine = 0
m.LinesNeeded = m.LinesNeeded + 1
ENDIF
OTHERWISE
m.OcuppiedInLine = m.OcuppiedInLine + m.SpaceWidth
ENDCASE
ENDFOR
m.NeededHeightForAnEditBox = m.LinesNeeded * m.LineHeight
RETURN m.NeededHeightForAnEditBox
ENDFUNC
----------------------------------
António Tavares Lopes