如何使组框的文本变为粗体而不是其中包含的控件的文本? [英] How do I make a group box's text bold but not the text of controls contained in it?

查看:79
本文介绍了如何使组框的文本变为粗体而不是其中包含的控件的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我去了,创建了一个包含大量控件的标签,其中大部分都包含在我称之为顶层组框中的控件中。现在,我决定让顶级组框的文本为粗体,但没有别的。但是,当我将顶级论坛框的字体设置为粗体时,其中包含的所有控件也将变为粗体,这是我不想要的。我可以将每个控件的粗体属性设置为false,但是似乎应该有一种更简单的方法来实现。有什么想法吗?



我可能会遗漏一些明显的东西,例如一个组合盒属性,使我瞪大了脸,如果真是这样,请道歉。



在此先感谢您的帮助。

解决方案

可以通过在GroupBox的标题上方放置标签来绕过此问题,但是我不一定推荐



<一旦您了解正在发生的事情以及发生的原因,就会出现更好的解决方案。问题是控件的字体(除其他外)是一个 ambient 属性,这意味着子控件继承其父/容器控件的属性。因此,如果将GroupBox设置为使用粗体字体,则默认情况下,其所有子控件都将自动继承粗体属性。



当然,默认情况下有键。仅当您未将子级属性明确设置为其他属性时,环境属性才适用。如果您不希望子控件为粗体,请全部选中它们并关闭粗体。父/容器的设置将不再覆盖新的自定义设置。



要使事情变得更加简单,可以将Panel控件添加到GroupBox,Dock / anchor中它将填充GroupBox控件的整个工作区,并将其设置为使用标准的非粗体字体。然后,环境控件的规则规定,默认情况下,添加到面板的子控件将 not 设为粗体。这样,您只需更改一个控件的font属性,而不是更改添加到GroupBox的每个子控件。



之所以比尝试在GroupBox标题上添加Label控件更好,是因为GroupBox旨在包含控件。您可以利用停靠和锚定属性来确保所有内容都正确排列,并且这样做时不必与设计者战斗,以确保自定义Label正确覆盖了GroupBox控件绘制的默认标签。 。此外,在运行时,例如,Label控件意外隐藏在GroupBox的后面,而且没人看到它时,您不会遇到Z顺序问题或其他重绘问题会在运行时抬起头来。以及许多其他潜在的灾难。


I went and created a tab containing a good amount of controls, most of which are contained within what I'll just call the top-level group box. Now I decide I'd like the text of the top-level group box to be bold, but nothing else. When I set the top-level group box's font to bold, however, all of the controls contained within it become bolded as well, which is what I don't want. I can set each individual control's bold property to false, but it seems like there should be an easier way to do this. Any ideas?

I'm probably missing something obvious, like a group box property that is staring me in the face--and apologize if this turns out to be the case.

Thanks in advance for any help.

解决方案

You could bypass the problem by placing a label over the caption for the GroupBox, but I wouldn't necessarily recommend this.

A better solution emerges once you understand what is happening and why it is happening. The issue is that a control's font (among other things) is an ambient property, meaning that child controls inherit their parent/container control's properties. So if you set the GroupBox to use a bold font, all of its child controls automatically inherit the bold property by default.

The key there is, of course, by default. Ambient properties only apply if you don't explicitly set the properties of the children to something else. If you don't want the child controls to be bold, select them all and turn off bold. The settings of the parent/container will no longer override the new custom settings.

To make things even easier, you can add a Panel control to your GroupBox, dock/anchor it to fill the entire client area of the GroupBox control, and set it to use a standard, non-bold font. Then, the rules of ambient controls stipulate that the child controls you add to the Panel will not be bold by default. This way, you only have to change the font property of one control as opposed to every child control that you add to the GroupBox.

The reason that this is better than trying to add a Label control over the GroupBox caption is because a GroupBox is designed to contain controls. You can take advantage of the docking and anchoring properties to make sure that everything gets arranged correctly, and you won't have to fight the designer when doing so to make sure that your custom Label correctly covers up the default label drawn by the GroupBox control. Additionally, you won't run into Z order issues or have other redrawing problems rear their ugly heads at runtime when, for example, the Label control gets accidentally hidden behind the GroupBox and no one can see it (and a host of other potential snafus).

这篇关于如何使组框的文本变为粗体而不是其中包含的控件的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆