如何在 WPF 中缩放文本大小以及 TextBox 大小?

发布于 2024-12-06 15:06:24 字数 132 浏览 3 评论 0原文

当我调整 WPF 应用程序的窗口大小时,所有文本框也会调整大小。问题是文本框中文本的大小没有改变。如何实现文本大小随文本框大小的缩放?

编辑:实际上,它是缩放,但我想让文本变大。因此,字体的高度应该接近文本框的高度。如何实现这一目标?

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 to make text bigger. So, the height of the font should be close to height of the textbox. How this can be achieved?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

说不完的你爱 2024-12-13 15:06:24

也许这样的东西会有所帮助

<Viewbox> 
    <TextBox/> 
</Viewbox>

只需使用 TextBox 的 maring 属性即可获得您想要的东西

maybe something like this will help

<Viewbox> 
    <TextBox/> 
</Viewbox>

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

温柔少女心 2024-12-13 15:06:24

我认为您可以使用此代码:\

在 TextBox 中的 SizeChange 事件中

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;
    }
}

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文