开发者

How to scale text's size along with TextBox's size in the WPF?

开发者 https://www.devze.com 2023-04-08 13:18 出处:网络
When I resize Window of the WPF application, all textboxes are also resized. The problem is that size of the text in the textboxes doesn\'t change. How can I achieve scaling the size of the text along

When I resize Window of the WPF application, all textboxes are also resized. The problem is that size of the text in the textboxes doesn't change. How can I achieve scaling the size of the text along with the size of the textboxes?

Edit: Actually, it is scaling, but I want开发者_Python百科 to make text bigger. So, the height of the font should be close to height of the textbox. How this can be achieved?


maybe something like this will help

<Viewbox> 
    <TextBox/> 
</Viewbox>

Just play with the maring property of the TextBox to get what you want


I Think You Can Use This Code:\

In SizeChange Event In TextBox

private void TextBox_SizeChanged(object sender, SizeChangedEventArgs e) 
{
    Size n = e.NewSize;
    Size p = e.PreviousSize;
    double l = n.Width / p.Width;
    if (l!=double.PositiveInfinity)
    {
        textbox1.FontSize = textbox1.FontSize * l;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消