c++ 如何控制wxCheckListBox项目?

xvw2m8pv  于 2023-02-14  发布在  其他
关注(0)|答案(3)|浏览(96)

我创建了一个wxCheckListBox并添加了一些项目。需要控制它们,如果任何项目被选中,我想做一些功能。实际上这是一个作弊dll应用程序。

wxArrayString pSkills;//this is array for my list
wxCheckListBox* SkillList = new wxCheckListBox(Panel1, wxID_ANY, wxPoint(3, 3), wxSize(150, 200), pSkills);//my list

我可以控制和加载任何我需要的项目。

bool MainFrame::IsChecked(unsigned int uiIndex) const
{
    if (IsChecked(uiIndex) == true)
    {
        return true;
    }
    else { return false; }
}

我用这个来控制。

SkillList->Bind(wxEVT_CheckListBox, &MainFrame::IsChecked, this);

我用这个没有工作:)

wmvff8tz

wmvff8tz1#

wxCommandEvent::IsChecked()只适用于复选框和菜单项中的事件。要获取列表框中项目N的当前状态,您需要使用SkillList->IsChecked(N)

hyrbngr7

hyrbngr72#

wxArrayString pSkills;
if (mClass == 201 || mClass == 205 || mClass == 206 || mClass == 101 || mClass == 105 || mClass == 106)
{
    pSkills.Add("Hell Blade");
    
}

wxCheckListBox* SkillList = new wxCheckListBox(Panel1, LIST_ID, wxPoint(3, 3), wxSize(150, 200), pSkills);
wxButton* ButtonStart = new wxButton(Panel1, wxID_ANY, _("START"), wxPoint(200, 20), wxSize(60, 30));
wxCheckBox* Check = new wxCheckBox(Panel1, wxID_ANY, _("START"), wxPoint(300, 10));

ButtonStart->Bind(wxEVT_BUTTON, &MainFrame::onStart, this);

int N = pSkills.Index("Hell Blade", true);

if (SkillList->IsChecked(pSkills.Index("Hell Blade")) == true)
{
    wxMessageBox(wxT("Work!"));
}

我确实喜欢这个,但没有工作:S @VZ。

q7solyqu

q7solyqu3#

请在下面找到代码片段。

class MainFrame
{
private:
    wxCheckListBox *SkillList;
public:
    MainFrame(/*set of parameters*/);
}

MainFrame::MainFrame(/*set of parameters*/)
{
    SkillList = new wxCheckListBox(Panel1, wxID_ANY, wxPoint(3, 3), wxSize(150, 200), pSkills);//my list
    SkillList->Bind( wxEVT_CHECKLISTBOX, &MainFRame::check, this );
}

void MainFrame::check(wxCommandEvent &event)
{
    if( SkillList->IsChecked( 0 ) )
        wxMessageBox( "Item 0 is checked" );
}

还有,我强烈建议你开始使用测径器。
查看代码,与现有代码进行比较,了解问题所在,然后才在程序中使用它。

相关问题