Working with Edit Boxes in Visual FoxPro

I had a circumstance where I wanted to show a potentially large piece of text in a read-only edit box in VFP.
 
I was changing the height of the box to only show the actual content therefore if I only had one line, I wanted the edit box to only take up one line in height.
 
Sounds simple, right?
 
Not quite. My other requirement was that the user should be able to change the alignment of the text in the box. Left Align worked beautifully but whenever I switched the Alignment to Center or Right, the text disappeared.
 
What was going on?
 
When using alignments other than Left, Edit boxes have to be at least a certain height to display properly. What is the magic number? As it turns out, it's 34.
 
Try it yourself:

x = CREATEOBJECT("Form")
x.
AddObject
("editbox","editbox")
x.
editbox.Visible
=.t.
x.
editbox.FontSize
= 8
x.
editbox.Value
= "Here is my text"
x.
Show
x.editbox.width = x.
Width
x.editbox.ScrollBars
= 0
x.
editbox.BorderStyle
= 0
x.
editbox.Alignment
= 2
x.
editbox.height
= 30    && Text disappears
x.editbox.height = 34    && Text Appears

 
Note: this is true in most versions of Visual FoxPro.

Comments

Popular Posts