概述

duilib中list控件默认情况样式比较简单,无法适应众多需求场景

扩展与原始list对比

原始实现效果:

扩展list效果:

扩展list的实现

1.duilib源代码的修改

首先修改CListHeaderItemUI类,该类表示的是list的表头,如下图:(修改源码后记得重新编译)

CControlUI类属于duilib基础控件类,CContainerUI是duilib的容器基类(duilib基础框架参考),容器,其实就是可以在里面添加,嵌套其他控件的东西,修改继承类,使其具有容纳其它控件的功能。

2.xml文件配置

list控件及表头配置

UpdateEepromReadPassword.xml

<?xml version="1.0"?>
<Window size="1280,760" caption="0,0,0,36" roundcorner="0,0"><Include source="lang.xml" /><Include source="font.xml" /><Include source="default.xml" /><VerticalLayout><TabLayout name="updateeepromtab"><VerticalLayout inset="30,30,30,30" bkcolor="#FFFFFFFF"><HorizontalLayout bkimage="list_bg.png" inset="0,0,0,0"><List name="listexeeprom" width="1213" bkcolor="#FFFFFFFF" inset="0,0,0,0" itemshowhtml="true" vscrollbar="true" hscrollbar="true" headerbkimage="file='list_header_bg.png'" itemalign="center" hscrollbar="false" menu="true"><ListHeader height="40" menu="true" scaleheader="true" bkcolor="#FFFFFFFF"><ListHeaderItem   font="3" scale="33" bodersize="1" bodercolor="#FFBDBDBD" textcolor="#FF151515" hotimage="file='list_header_hot.png'" pushedimage="file='list_header_pushed.png'" sepimage="file='list_header_sep.png'" sepwidth="1"><CheckBox name="select_eeprom_all" endellipsis="true" width="30" height="30"  selectedimage="file='Update\checkbox_p.png' dest='6,5,36,35'" normalimage="file='Update\checkbox_h.png' dest='6,5,36,35'"  /><Container  bkimage="file='Update\list_header_sep.png'" float="true" pos="40,0,41,40"/><Text name="multyupdate_eeprom_text_softname" text="软件名称" font="3" scale="10" float="true" pos="150,5,350,35"/></ListHeaderItem><ListHeaderItem text="本地最新版本"   font="3" scale="10" textcolor="#FF151515" hotimage="file='list_header_hot.png'" pushedimage="file='list_header_pushed.png'" sepimage="file='list_header_sep.png'" sepwidth="1"/><ListHeaderItem text="最新版本"   font="3" scale="15" textcolor="#FF151515" hotimage="file='list_header_hot.png'" pushedimage="file='list_header_pushed.png'" sepimage="file='list_header_sep.png'" sepwidth="1"/><ListHeaderItem text="可下载版本"  font="3" scale="10" textcolor="#FF151515" hotimage="file='list_header_hot.png'" pushedimage="file='list_header_pushed.png'" sepimage="file='list_header_sep.png'" sepwidth="1"/><ListHeaderItem text=""  font="3" endellipsis="true" scale="27" textcolor="#FF151515" bodersize="1" bodercolor="#FF151515" hotimage="file='list_header_hot.png'" pushedimage="file='list_header_pushed.png'" sepimage="file='list_header_sep.png'" sepwidth="1"><HorizontalLayout><Text name="multyupdate_eeprom_text_process" padding="15,10,0,5" text="0/0" /><Container  bkimage="file='Update\list_header_sep.png'" width="1" height="40"/><Button name="multyupdate_eeprom_btn" text="批量升级" padding="45,5,70,5" textcolor="#FFFFFFFF" font="3" align="center" valign="center" float="false" width="120" height="34" normalimage="file='Update\image_btn_oneclickupdate_nor.png'" hotimage="file='Update\image_btn_oneclickupdate_sel.png'" /></HorizontalLayout></ListHeaderItem></ListHeader></List>        </HorizontalLayout></VerticalLayout></TabLayout></VerticalLayout>
</Window>

 list扩展控件行列自定义配置

UpdateListItem.xml

<?xml version="1.0" encoding="UTF-8"?>
<Window><!-- <Font shared="true" id="1" name="微软雅黑" size="12" default="true" /> --><ListContainerElement><HorizontalLayout height="40"><HorizontalLayout width="30" padding="5,5,5,5"><CheckBox name="select_single" endellipsis="true" width="30" height="30" align="center" selectedimage="file='Update\checkbox_p.png' dest='0,0,30,30'" normalimage="file='Update\checkbox_h.png' dest='0,0,30,30'"  /></HorizontalLayout><HorizontalLayout width="350"><Label name="softname"  align="center" valign="center" textcolor="#FF727272" /></HorizontalLayout><HorizontalLayout width="150"><Label name="locallastversion"  align="center" valign="center" textcolor="#FF727272"  /></HorizontalLayout><HorizontalLayout width="150"><Label name="lastversion"  align="center" valign="center" textcolor="#FF727272" /></HorizontalLayout><HorizontalLayout width="129"><Combo name="enablevercom" font="3" width="129" height="48" align="center" valign="center" normalimage="file='Update\img_insert_combox_nor.png'"/></HorizontalLayout><HorizontalLayout width="330"><Label name="extend"  align="center" valign="center" textcolor="#FF727272" /></HorizontalLayout></HorizontalLayout></ListContainerElement>
</Window>

3.代码使用

//设置XXX升级列表表格
void CUpdatePage::ShowUpdateTableEEPROM(std::string StrSoftName = "XXX升级列表", std::string StrLocalVersion = "10", std::string StrNewVersion = "12", std::string StrEnableDownLoad = "12", std::string StrDownLoadStatus = "等待更新")
{wstring wStrSoftName = CStringHelper::s2ws(StrSoftName);wstring wStrLocalVersion = CStringHelper::s2ws(StrLocalVersion);wstring wStrNewVersion = CStringHelper::s2ws(StrNewVersion);wstring wStrEnableDownLoad = CStringHelper::s2ws(StrEnableDownLoad);wstring wStrDownLoadStatus = CStringHelper::s2ws(StrDownLoadStatus);int index = 0;CListUI* pList = static_cast<CListUI*>(m_PaintManager.FindControl(_T("listexeeprom")));if (NULL == pList){return;}CListContainerElementUI* pListElement = NULL;if (!m_dlgBuilder.GetMarkup()->IsValid()){pListElement = static_cast<CListContainerElementUI*>(m_dlgBuilder.Create(_T("UpdateListItem.xml"), (UINT)0, NULL, &m_PaintManager));}else{pListElement = static_cast<CListContainerElementUI*>(m_dlgBuilder.Create((UINT)0, &m_PaintManager));}//设置软件名称CLabelUI* pLab = static_cast<CLabelUI*>(m_PaintManager.FindSubControlByName(pListElement, _T("softname")));if (pLab != NULL){//pLab->SetFixedWidth(350);pLab->SetText(wStrSoftName.c_str());pLab->SetFont(3);pLab->SetBorderSize(1);pLab->SetBorderColor(0xFFBDBDBD);}//设置本地最新版本pLab = NULL;pLab = static_cast<CLabelUI*>(m_PaintManager.FindSubControlByName(pListElement, _T("locallastversion")));if (pLab != NULL){//pLab->SetFixedWidth(200);pLab->SetText(wStrLocalVersion.c_str());pLab->SetFont(3);pLab->SetBorderSize(1);pLab->SetBorderColor(0xFFBDBDBD);}//设置最新版本pLab = NULL;pLab = static_cast<CLabelUI*>(m_PaintManager.FindSubControlByName(pListElement, _T("lastversion")));if (pLab != NULL){//pLab->SetFixedWidth(130);pLab->SetText(wStrNewVersion.c_str());pLab->SetFont(3);pLab->SetBorderSize(1);pLab->SetBorderColor(0xFFBDBDBD);}//设置可下载版本CComboUI *pCom = static_cast<CComboUI*>(m_PaintManager.FindSubControlByName(pListElement, _T("enablevercom")));if (pLab != NULL){pCom->RemoveAll();CListLabelElementUI *pListElem1 = new CListLabelElementUI;pListElem1->SetText(wStrEnableDownLoad.c_str());pCom->Add(pListElem1);pListElem1 = new CListLabelElementUI;pListElem1->SetText(wStrEnableDownLoad.c_str());pCom->Add(pListElem1);pCom->SetBorderSize(1);pCom->SetBorderColor(0xFFBDBDBD);pCom->SelectItem(0);}//设置下载状态pLab = NULL;pLab = static_cast<CLabelUI*>(m_PaintManager.FindSubControlByName(pListElement, _T("extend")));if (pLab != NULL){//pLab->SetFixedWidth(330);pLab->SetText(wStrDownLoadStatus.c_str());pLab->SetFont(3);pLab->SetBorderSize(1);pLab->SetBorderColor(0xFFBDBDBD);}pListElement->SetFixedHeight(40);//pListElement->SetFixedWidth(1200);  //固定高度pListElement->SetUserData(_T("UpdateEEPROM"));index = pList->GetCount();//记录list与pListElement对应关系m_CurrentListOrder[index+ ListEepromBase] = pListElement;if (!pList->AddAt(pListElement, index)){delete pListElement;return;}}

4.列表的勾选与选中

单选一个,代码如下:

    int index = 0;CListUI* pListeeprom = static_cast<CListUI*>(m_PaintManager.FindControl(_T("listexeeprom")));if (pListeeprom){index = pListeeprom->GetCurSel();//当前所选行CControlUI *pControl = pListeeprom->GetItemAt(index);CListContainerElementUI* pItem = static_cast<CListContainerElementUI*>(pControl);CCheckBoxUI* pCheck = static_cast<CCheckBoxUI*>(m_PaintManager.FindSubControlByName(pItem, _T("select_single")));if (pCheck){if (pCheck->IsSelected()){pCheck->SetCheck(false);}else{pCheck->SetCheck(true);}}std::string str = CStringHelper::ws2s(pItem->GetUserData().GetData());//MessageboxDuilib::ShowMessageBox(NULL, str, "", 1);}

表头选中,全选与全不选,如下代码:

//升级界面列表全选
void CUpdatePage::UpdateEepromSelectAll()
{CCheckBoxUI *pCheckAll = static_cast<CCheckBoxUI*>(m_PaintManager.FindControl(_T("select_eeprom_all")));;if (pCheckAll){if (pCheckAll->IsSelected()){CListUI* pListeeprom = static_cast<CListUI*>(m_PaintManager.FindControl(_T("listexeeprom")));if (NULL == pListeeprom){return;}for (int i = 0; i < pListeeprom->GetCount(); i++){CControlUI *pControl = pListeeprom->GetItemAt(i);CListContainerElementUI* pItem = static_cast<CListContainerElementUI*>(pControl);CCheckBoxUI* pCheck = static_cast<CCheckBoxUI*>(m_PaintManager.FindSubControlByName(pItem, _T("select_single")));if (pCheck){pCheck->Selected(false);m_UpdateEepromSelect.clear();}}}else{CListUI* pListeeprom = static_cast<CListUI*>(m_PaintManager.FindControl(_T("listexeeprom")));if (NULL == pListeeprom){return;}for (int i = 0; i < pListeeprom->GetCount(); i++){CControlUI *pControl = pListeeprom->GetItemAt(i);CListContainerElementUI* pItem = static_cast<CListContainerElementUI*>(pControl);CCheckBoxUI* pCheck = static_cast<CCheckBoxUI*>(m_PaintManager.FindSubControlByName(pItem, _T("select_single")));if (pCheck){pCheck->Selected(true);m_UpdateEepromSelect.push_back(i);    //记录所选ID}}}}
}

5.实时修改列表头的信息

//设置模块下载个数进度
void CUpdatePage::SetEepromUpdateNum(std::string Str)
{std::wstring wstr = CStringHelper::s2ws(Str);CTextUI *pText = static_cast<CTextUI*>(m_PaintManager.FindControl(_T("multyupdate_eeprom_text_process")));if (pText){pText->SetText(wstr.c_str());}
}

外观效果如文章开头第二张图所示,还可以自行添加其它控件进行扩展,满足自己的需求。

duilib 中list控件的扩展相关推荐

  1. 玩转控件:对Dev中GridControl控件的封装和扩展

    清明节 清明时节雨纷纷 路上行人欲断魂 借问酒家何处有 牧童遥指杏花村 又是一年清明节至,细雨绵绵犹如泪光,树叶随风摆动.... 转眼间,一年又过去了三分之一,疫情的严峻让不少企业就跟清明时节的树叶一 ...

  2. 改进duilib的richedit控件的部分功能

    转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/41208207 如果要使用透明异形窗体功能,首先要改进duilib库让他本 ...

  3. 风影ASP.NET基础教学 5 验证控件(二) 扩展自己的验证控件

    前文回顾 我们之前提过了5种官方验证控件的方式. 下面我们来讲解编程方式验证和扩展自己的验证控件 以编程的方式验证asp.net控件 默认情况下,在页面回发到服务器时,页面初始化之后(即视图ViewS ...

  4. Duilib教程-控件练习

    一.控件消息的响应. 在HelloDuilib例子中,程序不能退出,在这里,我将添加一个关闭按钮,当点击它时,调用PostQuitMessage进行退出. 首先在界面的右上角添加一个关闭按钮,并取名为 ...

  5. android listview 滑动条显示_第七十六回:Android中UI控件之RecyclerView基础

    各位看官们,大家好,上一回中咱们说的是Android中UI控件之ListView优化的例子,这一回咱们说的例子是UI控件之RecyclerView.闲话休提,言归正转.让我们一起Talk Androi ...

  6. asp.net findcontrol html控件,findcontrol-在ASP.NET中查找控件的更好方法

    findcontrol-在ASP.NET中查找控件的更好方法 我有一个复杂的asp.net表单,在一个表单中甚至有50到60个字段,例如FindControl(),在MultiView中我有GridV ...

  7. LabVIEW中ActiveX控件、ActiveX服务器和类型库注册

    LabVIEW中ActiveX控件.ActiveX服务器和类型库注册 如何在计算机上手动注册ActiveX控件(.ocx ).ActiveX服务器(.DLL和.EXE)以及类型库(.TLB )? 在L ...

  8. delphi多线程超时控Delphi7中Indy控件对于网络数据的接收

    1.引言 随着我国经济和社会的发展,水资源的科学管理与合理配置显得越来越重要.而获取大量的.实时的.动态的水资源及其相关信息则是实现水资源科学管理的基础.传统的水资源信息获取采用人工抄取数据后逐级的方 ...

  9. duilib修复ActiveXUI控件bug,以支持flash透明动态背景

    转载请说明原出处,谢谢~~ 昨天在QQ控件里和同学说起QQ2013登陆窗体的开发,从界面角度考虑,单单一个登陆界面是很容易做出来的.腾讯公司为了防止各种盗号行为可谓煞费苦心,QQ2013采用了动态背景 ...

  10. .NET中添加控件数组

    作者:cuike519的专栏   http://blog.csdn.net/cuike519/ 添加控件数组 在.NET里面我好像没有找到有关于控件数组的说明,但是前两天偶在网上看到了一篇关于如何在. ...

最新文章

  1. 卡巴斯基工业基础设施专用网络安全解决方案
  2. 设计模式——控制反转依赖注入
  3. SAP Spartacus ComponentData的提前subscription
  4. pyramid新建项目
  5. 前端学习(1667):前端系列实战课程之拖拽
  6. 改进了一下这个游戏的输出及思路,是不是好玩多了??:)
  7. u盘锁电脑_手机空间不足?U盘来辅助,一招解决问题
  8. Notepad2 v4.22.03 (r4130) 轻量级文本编辑器。可替换系统记事本
  9. 清华大学计算机课程对应教材,清华大学计算机专业大一到四的课程 教材详细名字...
  10. 微博 用户画像_新浪微博数据采集方法以及数据分析(用户画像) - 八爪鱼采集器...
  11. PHP是世界上最好的语言
  12. Ionic页面传参跳转
  13. error TS2687:All declarations of ‘**‘ must have identical modifier
  14. (三十)信号——信号产生原因以及信号处理行为的简介
  15. 阿里云办公安全产品专家高传贵:零信任,让全球办公安全更简单
  16. Python爬虫 | 代理IP的获取和使用
  17. day32_创建Mysql账户,以及python操作Mysql
  18. 工程训练大赛物流小车_宁大机械学子在工程训练省赛中斩获佳绩,取得历史性突破...
  19. iPhone通话质量和基带有关?2招教你检测手机是什么基带!
  20. IDEA使用单元测试对数据库的insert语句进行测试,出现添加多条问题的解决方案

热门文章

  1. 更新时卡住_7月2日全区1.693版本更新公告
  2. 力特usb转232驱动程序下载_电脑USB接口、U盘接口不能使用的原因及解决方法
  3. 求一个任意实数的算术平方根的算法设计_感恩!面试必刷100道算法题
  4. signature=29f9d891eda46899a29591e507a569b3,NEW MARKER OF BREAST TUMORS FROM THE LUMINAL-B SYBTYPE
  5. bootstrapmodel确认操作框_Bootstrap使用模态框modal实现表单提交弹出框
  6. 去重 属性_亿万级海量数据去重软方法,spark/flink/mr等通用
  7. 动态规划实战8 leetcode-53. Maximum Subarray
  8. Introduction to Computer Networking学习笔记(五):ARP协议(Address Resolution Protocol)
  9. python创建线程_Python 创建线程的方法
  10. 分别用switch语句和if语句实现键盘录入月份,输出对应的季节