zoukankan      html  css  js  c++  java
  • mfc CListBox

    通过ID操作对象
    CListBox(列表框)控件
    CListBox类常用成员
    CListBox插入数据
    CListBox删除数据
    CListBox运用示例
    
     
    一、CListBox类常用成员
     
    CListBox::ResetContent//清空组合框内容
    void ResetContent( );
    
    CListBox::AddString//添加lpszString 至组合框尾部
    int AddString( LPCTSTR lpszString );
    
    CListBox::DeleteString//删除nIndex行
    int DeleteString( UINT nIndex );
    
    CListBox::InsertString //在nIndex行后,插入行
    int InsertString( int nIndex, LPCTSTR lpszString );
    
    CListBox::SelectString //可以选中包含指定字符串的行
    int SelectString( int nStartAfter, LPCTSTR lpszString );
    
    CListBox::FindString //可以在当前所有行中查找指定的字符传的位置,nStartAfter指明从那一行开始进行查找。 
    int FindString( int nStartAfter, LPCTSTR lpszString ) const;
    
    CListBox::GetCount //获取行数
    int GetCount( ) const;
    
    CListBox::GetCurSel//获取当前选中行的行号
    int GetCurSel( ) const;
    
    CListBox::SetCurSel(n)//设置第n行内容为显示的内容
    int SetCurSel( int nSelect );
    
    int CListBox::SetItemHeight( int nIndex, UINT cyItemHeight );//设置一个项的高度,注意:列表框具有
    //LBS_OWNERDRAWVARIABLE风格才可以单独设置一个项的高度,否则是所有项的高度
    //------------------------上述函数与 CListBox::与CComboBox::::几乎相同
    
    int CListBox::GetText( int nIndex,CString &rString ) const;//根据索引获得项文本  类似CComboBox::GetLBText
    
    
     
    二、 代码示例
    void CDialog_ListBoxTest::OnBnClickedButton1()
    {
        // TODO: 在此添加控件通知处理程序代码
        CListBox* plstbox=(CListBox*)GetDlgItem(IDC_LIST1);
        plstbox->AddString(L"xxxxxxxx");
        
    }
    
    int CDialog_ListBoxTest::OnInitDialog(void)
    {
        CDialog::OnInitDialog();
        CListBox* plstbox=(CListBox*)GetDlgItem(IDC_LIST1);
        plstbox->AddString(L"1111");
        plstbox->AddString(L"2222");
        plstbox->AddString(L"3333");
        return 0;
    }
    
    void CDialog_ListBoxTest::OnBnClickedButton2()
    {
        // TODO: 在此添加控件通知处理程序代码
        CListBox* plstbox=(CListBox*)GetDlgItem(IDC_LIST1);
        //plstbox->DeleteString(0); //删除指定行
        plstbox->DeleteString(plstbox->GetCurSel());
    }
    
    void CDialog_ListBoxTest::OnLbnDblclkList1()
    {
        // TODO: 在此添加控件通知处理程序代码
        //
        CListBox* plstbox=(CListBox*)GetDlgItem(IDC_LIST1);
        CEdit * pedt=(CEdit*)GetDlgItem(IDC_EDIT1);
        WCHAR ws[256];
        plstbox->GetText(plstbox->GetCurSel(),ws); //获取选中文本存到ws
        //把文本送到编辑框里
        pedt->SetWindowText(ws);
  • 相关阅读:
    解决执行sql脚本报错:没有足够的内存继续执行程序。
    正则表达式学习
    art-template模板引擎循环嵌套
    textarea 设置最长字数和显示剩余字数
    display:table-cell
    js 发送 ajax 是数组 后台循环 发送json 到前台的方法
    js 函数内数据调用
    Angular 原文输出
    Angular 路由跳转
    JQ 按钮实现两种功能
  • 原文地址:https://www.cnblogs.com/whzym111/p/6214597.html
Copyright © 2011-2022 走看看