vc复选框:使VC中CListBox带有复选框来源: 发布时间:星期四, 2009年2月12日 浏览:102次 评论:0
由于实际需要在项目中需要使用个带有复选框列表Control控件没错VB、Delphi……里现成就有但由于项目是VC工程VC里现成CListBox或CListCtrl都没有复选框说到这里高手们可能会说简单自已重绘个或者偷懒点思路方法也可以去网上找个别人做好现成类来用 其实还有个更轻松思路方法网上找到这样段话: How to use the CCheckListBox in a dialog box Create in your resource file an ordinary list box in a dialog box. Whichever other attributes that you choose, the list box must be ownerdrawn and the hass attribute. Assume that in this , you have assigned an ID of IDC_CHECKLISTBOX to the listbox . Create an instance of a CCheckListBox object in the header file of your dialog box. CCheckListBox m_CheckListBox; Over-ride _disibledevent=> iState; iState = m_CheckListBox.GetCheck(iIndex); 思路方法很巧移花接木 MFC有个CCheckListBox类支持复选框风格所以我们可以直接使用ListBoxControl控件然后化时把它子类化成CCheckListBox再设置下风格参数就行但要注意下成功关键是要修改ListBoxControl控件两处属性分别是Owner draw设置为Fixed(LBS_OWNERDRAWFIXED)Has s设置为True(LBS_HASSTRINGS)否则不成功运行时报错 具体实现步骤举例如下—— 1、首先在窗口上拖放个ListBoxControl控件假设其资源ID为IDC_LIST1; 2、如上所述修改该ListBoxControl控件属性(LBS_OWNERDRAWFIXED | LBS_HASSTRINGS); 3、定义CCheckListBox对象在窗口类头文件里; [Page] // XXXDlg.h CCheckListBox m_CheckList; 4、然后在CPP文件里化地方写下两行; // XXXDlg.cpp BOOL CXXXDlg::OnInitDialog ...{ // ... m_CheckList.SubDlgItem(IDC_LIST1, this); // IDC_LIST1是ListBoxControl控件资源ID m_CheckList.SetCheckStyle(BS_AUTOCHECKBOX); // ... } OK就这么简单!m_CheckListBox.AddString(\"...\");加几条数据看看是不是有复选框了! 判断复选框是否被选中也很简单m_CheckListBox.GetCheck(nIndex);就行! 以上在VC6、8中均测试通过 www. 0
相关文章读者评论发表评论 |
|