How to resize the font size - WPF?

Asked

Viewed 160 times

0

The following code works with winforms:

while (label1.Width < System.Windows.Forms.TextRenderer.MeasureText(label1.Text,
    new Font(label1.Font.FontFamily, label1.Font.Size, label1.Font.Style)).Width)
{
    label1.Font = new Font(label1.Font.FontFamily, label1.Font.Size - 0.5f, label1.Font.Style);
}

How can I do this in WPF ? The idea is to make a autoresize in a textbox until every word fits.

Follow the image below, which in the last line was cut, I want to decrease the font size until show all words.

inserir a descrição da imagem aqui

The photo above is not a label, is a textbox.

Any idea to do in WPF ?

1 answer

1


You can use a Viewbox to auto resize the font size.

Example

<Viewbox>
     <TextBox Text="TESTE"/>
</Viewbox>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.