Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change font size at run time

Status
Not open for further replies.

earlrainer

Programmer
Mar 1, 2002
170
IN
Hey guys,

my problem is I have a dbedit box on my form.
but sometimes the data it contains is too big to be seen completely...so I was thinking maybe if I can change the font size automatically so that entire data can be seen.

but i dont know how this can be done.

any help guys???
 
Have you tried changing the dbedit1.Font.Size at runtime ? You may be restricted just how small you can go.

If the data in the DBEdit is for readonly purposes, you could use a DBText and set it's AutoSize property to true.

lou
 
Well, have you tried to set the autosize of the TDBedit to True?

If you want to do it manually, it should be enough with:

(...)
If Length(TDBedit1.Caption)>MaxDisplayedLength Then
Begin
TDBedit.Font.Size:=SmallSize
Refresh; //Very Important!!!!
End;

Hope this helps,
Dani.
 
hi BSide

I believe Autosize on a TDBEdit sets the height only and not the width.

lou
 
Code:
    mycanvas.Font.Height := initialvalue;
    while (mycanvas.Font.Height > 1)
      and (mycanvas.TextWidth(mydbedit.Text) > mydbedit.Width) do
        mycanvas.Font.Height := mycanvas.Font.Height - 1;                

    mydbedit.Font.Height := mycanvas.Font.Height;
In other words, while the text is too wide, shrink it.

Put this in the dbedit's OnChanged event, so it'll get called every time the user types a key.

You can use any old canvas that's lying around as mycanvas; you can create one or just use the one you get free with a form. -- Doug Burbidge mailto:doug@ultrazone.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top