How to check MFC read-only but keep text enabled?

It seems that disabling the checkbox through the Disabled property also highlights the label. Does anyone know how to enable signature but disable input?

EDIT

Based on Paul's idea, I did the following (now that I realized that the static label and checkbox have a transparent property).

  • Added a couple of flags.
  • Check the boxes in nothing.
  • Set the transparent property flag to true.
  • Add a check box next to the check box.
  • Change the transparent label property to true.
  • Expand the checkboxes to enable the shortcut (to click on the label, this checkbox will change).

But it gives me very strange results. When I check the box above the label, it covers the label, although both are transparent. Again, I'm new to MFC (I'm a C # guy), so maybe I missed something.

+3
source share
5 answers

A quick and easy workaround is to not use the checkbox text element (set it to ""), size uncheck only the square that is clickable, and simply place a check mark next to that check box.

, , , . , , . , , . ( . , , .)

( UFC MFC), .

. -:

: ( )

[x "checkbox text"]

: ( )

[x][label: "label text"]

- :

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

onClick , .

void CMyDialog::OnBnClickedMyCheckBox()
{
    m_myCheckBox.SetCheck(!m_myCheckBox.GetCheck());    
}
+3

Auto .

, , , .

: , . True, Dialog Data Exchange.

Type: Bool, Default: True.

+3

You can cancel a selection in a function by clicking if no other condition exists.

0
source
void SetCheckBoxReadOnly(CButton* i_checkBox, bool i_readOnly)
{
    if (!i_checkBox)
    {
        return;
    }

    // Clear/set "Auto" property
    if (i_readOnly)
    {
        i_checkBox->ModifyStyle(BS_AUTOCHECKBOX, BS_CHECKBOX);
    }
    else
    {
        i_checkBox->ModifyStyle(BS_CHECKBOX, BS_AUTOCHECKBOX);
    }

    // Set a grey background for check square - looks like disabled :)
    i_checkBox->SetState(i_readOnly ? TRUE : FALSE);
}
0
source

Source: https://habr.com/ru/post/1737585/


All Articles