我如何制作一个没有透明文本的 TCheckbox(即:它忽略主题)?
我如何制作一个没有透明文本的 TCheckbox(即:它忽略主题)?我被要求做一些非常规的事情——在组框标题的位置放置一个复选框。
在XP中,它看起来不太好。
(来源:xrw.bc.ca)
接下来,我想我应该尝试 SetWindowTheme(CheckBox1.Handle, ' ', ' ') 我在互联网上听说过。然后你会得到一个白色背景,但它不会用控件的颜色绘制。
(来源:xrw.bc.ca)
我们怎样才能做到这一点?
谢谢你! 议员
how can i make a TCheckbox without transparent text (ie: it ignores themes)? i've been asked to do something unconventional--put a checkbox on the place of the caption of a group box.
in XP, it doesn't look very good.
(source: xrw.bc.ca)
next, i thought i'd try SetWindowTheme(CheckBox1.Handle, ' ', ' ') i'd heard about on the internet. then you get a white background but it won't paint with the color of the control.
(source: xrw.bc.ca)
how can we do this?
thank you!
mp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一个简单的解决方案是将足够的空格字符放入 TGroupBox.Caption 属性中。更复杂的解决方案是从 TGroupBox 派生并在 Paint 方法中使用 FillRect/DrawParentBackground 来覆盖线条。
A simple solution would be to put enough space characters into the TGroupBox.Caption property. A more complicated solution would be to derive from TGroupBox and use FillRect/DrawParentBackground in the Paint method to over paint the line.
过去我只是在复选框后面添加了一个空白的 TLabel。
虽然这使得维护有点痛苦
In the past I have just added a blank TLabel behind the checkbox.
It makes maintenance a bit of a pain though
TCheckbox 上的 Color 属性不可以做到这一点吗?
在上面的图片中,我认为如果将颜色设置为与控件的颜色相同,您就可以得到您想要的。这将隐藏作为控件一部分的文本下方的线条并使其融入其中。
由于您不会提前知道颜色(由于不知道正在使用什么主题),因此您需要动态地在创建表单时运行时,例如:
Doesn't the Color property on the TCheckbox do it?
In your picture above, I think you can get what you want if you set the Color to same as the color of the control. That will hide the lines under the text that is part of the control and make it blend in.
Since you won't know the color in advance (due to not knowing what theme is in use) you'll want to do it dynamically at run time when the form is created, e.g.:
谢谢大家的回答。最后,我这样做了:
以编程方式用空格将组框标题的开头填充到正确的宽度。
以编程
将复选框(不带标题)移动到标题区域。
这不是一个完美的解决方案,但看起来还可以。
thank you all for your answers. in the end, i did this:
padded the beginning of the groupbox caption programmatically with spaces to the correct width.
move the checkbox (without a caption) into the caption area.
it's not a perfect solution but it seems ok.