• CListBox(列表框)控件


    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);

       

    }

  • 相关阅读:
    MySQL和B树的那些事
    记一次临时抱佛脚的性能压测经历
    zookeeper api
    zookeeper笔记
    Mysql优化系列(1)--Innodb重要参数优化
    搞懂MySQL InnoDB B+树索引
    我以为我对Mysql索引很了解,直到我遇到了阿里的面试官
    HDFS原理概念扫盲
    设计原则
    设计模式 6大则
  • 原文地址:https://www.cnblogs.com/15157737693zsp/p/3840161.html
Copyright © 2020-2023  润新知