如何使MFC复选框为只读但保持文本启用状态? [英] How do I make MFC checkbox read-only but keep text enabled?

查看:249
本文介绍了如何使MFC复选框为只读但保持文本启用状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎通过Disabled属性禁用复选框也会使标题变灰.有人知道如何保持字幕启用但禁用输入吗?

It seems that disabling a checkbox through the Disabled property also grays out the caption. Does anyone know how to keep the caption enabled but disable input?

编辑

根据Paul的想法,我做了以下操作(现在我已经知道静态标签和复选框具有透明属性).

Based on Paul's idea, I've done the following (now that I figured out that the static label and checkbox has a transparent property).

  1. 添加了几个复选框.
  2. 将复选框标题设置为空.
  3. 将复选框透明属性设置为true.
  4. 在复选框旁边添加几个标签.
  5. 将标签的透明属性更改为true.
  6. 展开复选框以包含标签(因此,单击标签将触发复选框进行更改).

但是,这给了我非常奇怪的结果.当我在标签上展开复选框时,即使它们都是透明的,它也会覆盖标签.再次,我是MFC的新手(我是C#专家),所以也许我错过了一些东西.

But, this gives me very weird results. When I expand the checkbox over the label, it covers the label even though both are transparent. Again, I'm new to MFC (I'm a C# guy) so maybe I'm missing something.

推荐答案

快速简单的解决方法是不使用复选框的文本成员(将其设置为"),将复选框的大小缩小为仅可单击的正方形然后只需在复选框旁边放置一个标签即可.

The quick and simple workaround is to not use the checkbox' text member (set it to ""), size down the checkbox to just the click-able square and simply place a label next to the checkbox.

您可以创建一个自定义控件,其中包含一个复选框和一个标签,以使您可以重用,从而获得更多帮助.这也将是使自定义复选框表现出最终用户预期效果的更简单方法,例如能够在单击标签以及复选框本身时将复选框设置为选中或未选中. (简单的解决方案不会自动将标签和复选框相关联.您可以在表单中进行编码,但是如果您倾向于重用该范式,可能会变得很丑陋.)

To get a little fancier you could create a custom control that hosts a checkbox and a label which would enable reuse. It wold also be easier way to make the custom checkbox behave as expected for the end user e.g. being able to set the checkbox to selected or unselected when the label gets clicked as well as the checkbox itself. (The simple solution would not automatically relate the label and the checkbox. You could code that within the form but that might get ugly fast if you tend to reuse the paradigm.)

您还可以四处寻找第3方复选框控件(那里有许多MFC UI库),但这可能会显得过大.

You could also look around for a 3rd-party checkbox control (there are numerous MFC UI libraries out there) but that might be overkill.

查看此伪布局:

您有:(单独的复选框控件)

You have this: (lone check box control)

[x "checkbox text"]

这样布置:(标签控件在复选框旁边对齐)

Lay it out like this: (label control aligned right next to the checkbox)

[x][label: "label text"]

使用类似以下方式处理标签的clicked事件:

Handle the clicked event of the label with something like:

void OnLabelClick(...) {
    if (checkBox.Enabled)
        checkBox.Checked = !checkBox.Checked;
}

这篇关于如何使MFC复选框为只读但保持文本启用状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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