如何将 GroupBox 标题与其内容分开设置样式?

发布于 2024-10-04 01:15:50 字数 227 浏览 3 评论 0原文

我正在开发一个 WinForms 应用程序,在一个表单上,我使用 GroupBox 将相关控件分组在一起。我想以特定的方式设置标题的样式(例如,将标题设为粗体)。通过更改 GroupBox 的样式,我可以自定义标题,但它也会更改 GroupBox 内控件的样式。

到目前为止,还没有那么多子控件,所以我单独将它们的样式重置回默认值,但我认为必须有更好的方法......但到目前为止我还没有弄清楚。

有办法吗?

I'm developing a WinForms application and on one form, I use a GroupBox to group related controls together. I would like to style the caption in a particular way (e.g. making the caption bold). By altering the styling for the GroupBox, I can customise the caption, but it also alters the styling for controls within the GroupBox.

So far, there aren't that many child controls, so I'm individually resetting their styles back to the default, but I figure there has to be a better way... but I haven't figured it out so far.

Is there a way?

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

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

发布评论

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

评论(3

难以启齿的温柔 2024-10-11 01:15:50

最简单的方法是在 GroupBox 中放置另一个面板,这样您只需重置字体一次。

还有很多其他解决方案,但它们都需要更多代码。这使它保持美观和简单。

The easiest way would be to put another panel inside the GroupBox, so that you only have to reset the font once.

There are plenty of other solutions, but they all require a lot more code. This keeps it nice and simple.

十年九夏 2024-10-11 01:15:50

Control.Font(以及其他与样式相关的属性)的实现方式是,如果它没有显式设置,它会向其父级请求Font。显然,这意味着您必须为所有子控件单独设置它,以确保它们不会受到父样式更改的影响。

也许您应该看看所有者绘制的 GroupBox 标题?

Control.Font (and other style-related properties) is implemented in such a way that it asks its parent for Font if it does not have explicitly set one. Obviously, this means that you would have to set it individually to all of the child controls to make sure they are not affected by changes in parent style.

Maybe you should take a look at owner-drawing the GroupBox caption?

深者入戏 2024-10-11 01:15:50

我解决了这个问题,删除了默认组标题,并在默认组标题的同一位置在组上添加了一个粗体的新标签。

I Solved this problem removing the default group caption and add a new label witch bold over the group at same place default group caption was.

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