MFC入门示例之组合框(CComboBox)、列表框(CListBox)

 1 //添加按钮点击事件
 2 void CMFCApplication4Dlg::OnBnClickedButton1()
 3 {
 4     CString strText;
 5     //获取文本框的值
 6     GetDlgItemText(IDC_EDIT1, strText);
 7     //添加到组合框中
 8     m_cmb_demo.AddString(strText);
 9     m_cmb_demo.SetCurSel(m_cmb_demo.GetCount() - 1);//设置当前选中
10     //添加到列表框中
11     m_list_demo.AddString(strText);
12     m_list_demo.SetCurSel(m_list_demo.GetCount() - 1);//设置当前选中
13 }
14 
15 //删除按钮点击事件
16 void CMFCApplication4Dlg::OnBnClickedButton2()
17 {
18     //删除当前选中
19     int nIndex;
20     nIndex = m_cmb_demo.GetCurSel();
21     if (nIndex > -1) {
22         m_cmb_demo.DeleteString(nIndex);
23         if (nIndex < m_cmb_demo.GetCount()) 
24             m_cmb_demo.SetCurSel(nIndex);
25         else 
26             m_cmb_demo.SetCurSel(0);
27     }
28     
29     nIndex = m_list_demo.GetCurSel();
30     if (nIndex > -1) {
31         m_list_demo.DeleteString(nIndex);
32         if (nIndex < m_list_demo.GetCount())
33             m_list_demo.SetCurSel(nIndex);
34         else 
35             m_list_demo.SetCurSel(0);
36     }
37 } 

 

转载于:https://www.cnblogs.com/runtimeexception/p/9209915.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值