MFC:如何根据单击按钮交替显示两个组框? [英] MFC : How to display two group boxes alternatively based on a button click?
问题描述
我有两个分组框,每个分组框包含 2 个单选按钮,每个参考图.我需要一种机制,其中 button1 的 init 阶段值显示文本Group box 2",并且对话框中显示的当前分组框是分组框 1.当我单击单选按钮 1 = Group Box 2 时,当前会发生以下情况:
I have two group boxes containing 2 radio button each refer figure. I need a mechanism wherein the init stage value of button1 shows text "Group box 2" and the current group box displayed on the dialog is group box 1. As I click on the radio button1 = Group Box 2 currently the following happens:
按钮 1 中的文本更改为分组框 1
The text in button 1 changes to group box 1
组框2显示在对话框中
隐藏分组框 1
我知道如何隐藏分组框我不确定是切换部分
I know how to hide the group boxes what I am not sure is the toggling part
推荐答案
您可以使用以下方法:创建一个函数来显示/隐藏相关组框并更新按钮上的文本.
You can use the following approach: Create a function that will show/hide the relevant group box and update the text on the button.
您可以使用此功能来显示/隐藏控件和组.接收到的参数是电台ID和分组框.
You can use this function to show/hide the controls and the group. The parameter received are the IDs of the radios and the group box.
void CMFCApplication2Dlg::ShowHideControls(BOOL hide, int groupID, int radio1ID, int radio2ID)
{
GetDlgItem(groupID)->ShowWindow(hide ? SW_HIDE : SW_NORMAL);
GetDlgItem(radio1ID)->ShowWindow(hide ? SW_HIDE : SW_NORMAL);
GetDlgItem(radio2ID)->ShowWindow(hide ? SW_HIDE : SW_NORMAL);
}
创建一个控制切换的函数:
Create a function that control the toggling:
void CMFCApplication2Dlg::ToggleGroup(BOOL group1Visible)
{
ShowHideControls(group1Visible, IDC_MY_GROUP, IDC_RADIO1, IDC_RADIO2);
ShowHideControls(!group1Visible, IDC_MY_GROUP2, IDC_RADIO3, IDC_RADIO4);
CString txt;
txt.Format(L"Group Box %d", group1Visible ? 1 : 2);
GetDlgItem(IDC_BUTTON_TOGGLE)->SetWindowText(txt);
}
从以下位置调用 ToggleGroup
:
a) OnInitDialog
带有 FALSE 参数.
a) OnInitDialog
with FALSE parameter.
b) 在按钮单击事件处理程序中.
b) In button click event handler.
这篇关于MFC:如何根据单击按钮交替显示两个组框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!