📦 第一部分:通用基础属性 (CControlUI)

所有控件均继承自 CControlUI,因此所有控件都支持以下属性。
CControlUI
属性名 类型 默认值 功能说明
namestring控件的唯一标识符(ID),用于在代码中查找控件
textstring""控件显示的文本内容。支持 {\n} 换行
posrect0,0,0,0绝对坐标位置 (left,top,right,bottom)
floatbool/percentfalse是否浮动,可设置百分比位置
floatalignstring浮动对齐:left,top,right,bottom,center,vcenter
paddingrect0,0,0,0外边距 (left,top,right,bottom)
bkcolorcolor0x00000000背景颜色 (ARGB 16进制,如 #FFFF0000)
bkcolor2color0x00000000背景渐变色2
bkcolor3color0x00000000背景渐变色3
gradientstring设置渐变方向
bkimagestring背景图片,支持属性如 file='x.png' source='0,0,10,10'
foreimagestring前景图片路径(绘制在文字之上)
bordersizerect/int0边框宽度 (left,top,right,bottom) 或统一宽度
bordercolorcolor0x00000000边框颜色
focusbordercolorcolor0x00000000获得焦点时的边框颜色
borderroundsize0,0圆角大小 (width,height)
widthint0控件固定宽度
heightint0控件固定高度
minwidthint0最小宽度
minheightint0最小高度
maxwidthint9999最大宽度
maxheightint9999最大高度
visiblebooltrue是否可见
enabledbooltrue是否启用
mousebooltrue是否响应鼠标事件
keyboardbooltrue是否响应键盘事件
tooltipstring鼠标悬停提示文本
userdatastring用户自定义字符串数据
menuboolfalse是否启用右键菜单
cursorstringarrow鼠标光标形状 (arrow, hand, ibeam 等)

📦 CContainerUI 容器基类

所有布局控件的基类,定义了子控件管理和滚动条属性。
CControlUI CContainerUI
属性名 类型 默认值 功能说明
insetrect0,0,0,0容器内边距 (left,top,right,bottom)
childpaddingint0子控件之间的间距
hscrollbarboolfalse是否启用水平滚动条
vscrollbarboolfalse是否启用垂直滚动条
hscrollbarstylestring水平滚动条样式
vscrollbarstylestring垂直滚动条样式
mousechildbooltrue子控件是否可以响应鼠标事件
scrollstepsizeint0滚动步长
XML 示例
<Container width="300" height="200" inset="10,10,10,10" bkcolor="#FFFFFFFF" bordercolor="#FF000000" bordersize="1">
    <Button text="我是子控件" width="100" height="30" />
</Container>

📐 CVerticalLayoutUI 垂直布局

子控件从上到下垂直排列。
CControlUI CContainerUI VerticalLayout
属性名 类型 默认值 功能说明
sepheightint0拖动分隔条的高度,设置 >0 可在底部启用拖动调整大小
sepimmboolfalse拖动分隔条时是否即时刷新布局
XML 示例
<VerticalLayout width="200" height="300" bkcolor="#FFEEEEEE" inset="5,5,5,5" childpadding="5">
    <Button text="按钮 1" height="30" />
    <Button text="按钮 2" height="30" />
    <Label text="自动填充区域" bkcolor="#FFAAAAAA" />
</VerticalLayout>

📐 CHorizontalLayoutUI 水平布局

子控件从左到右水平排列。
CControlUI CContainerUI HorizontalLayout
属性名 类型 默认值 功能说明
sepwidthint0拖动分隔条的宽度,设置 >0 可在右侧启用拖动调整大小
sepimmboolfalse拖动分隔条时是否即时刷新布局
XML 示例
<HorizontalLayout width="400" height="50" bkcolor="#FFDDDDDD" inset="5,5,5,5" childpadding="10">
    <Button text="左侧" width="80" />
    <Label text="中间文本" />
    <Button text="右侧" width="80" />
</HorizontalLayout>

📐 CTileLayoutUI 平铺布局

子控件像瓷砖一样排列,支持固定列数。
CControlUI CContainerUI TileLayout
属性名 类型 默认值 功能说明
columnsint1列数,指定每行显示的控件数量
itemsizesize0,0每个子项的固定大小 (width,height)
XML 示例
<TileLayout width="400" height="300" columns="3" itemsize="100,100" inset="10,10,10,10" childpadding="10">
    <Button text="Item 1" />
    <Button text="Item 2" />
    <Button text="Item 3" />
    <Button text="Item 4" />
</TileLayout>

📐 CTabLayoutUI 标签页布局

类似于卡片堆叠,同一时间只显示一个子控件。通常配合 Option 控件使用。
CControlUI CContainerUI TabLayout
属性名 类型 默认值 功能说明
selectedidint0默认选中的子控件索引(从0开始)
XML 示例
<VerticalLayout>
    <HorizontalLayout height="30">
        <Option text="Tab 1" group="tabs" selected="true" bindtablayoutname="my_tab_layout" bindtabindex="0" />
        <Option text="Tab 2" group="tabs" bindtablayoutname="my_tab_layout" bindtabindex="1" />
    </HorizontalLayout>
    
    <TabLayout name="my_tab_layout" selectedid="0">
        <VerticalLayout bkcolor="#FFFF0000">
            <Label text="Page 1 Content" align="center" />
        </VerticalLayout>
        <VerticalLayout bkcolor="#FF00FF00">
            <Label text="Page 2 Content" align="center" />
        </VerticalLayout>
    </TabLayout>
</VerticalLayout>

📐 CChildLayoutUI 子布局加载器

用于加载外部 XML 文件作为子布局,实现界面模块化。
CControlUI CContainerUI ChildLayout
属性名 类型 默认值 功能说明
xmlfilestring外部 XML 文件的路径
XML 示例
<VerticalLayout>
    <Label text="Header" height="50" />
    <ChildLayout xmlfile="layouts/content_part.xml" />
    <Label text="Footer" height="50" />
</VerticalLayout>

T CLabelUI 文本标签

基础文本显示控件。
CControlUI Label
属性名 类型 默认值 功能说明
alignstringleft水平对齐:left, center, right
valignstringcenter垂直对齐:top, vcenter, bottom
fontint-1字体索引
textcolorcolor0文本颜色
disabledtextcolorcolor0禁用状态颜色
textpaddingrect0,0,0,0文本内边距
showhtmlboolfalse是否启用 HTML 渲染 (支持 <b>, <i>, <c color>)
endellipsisboolfalse文本过长显示省略号 (...)
wordbreakboolfalse自动换行
XML 示例
<Label text="这是一个标签" font="0" textcolor="#FF000000" align="center" valign="vcenter" />
<Label text="{c #FF0000}红色文字{/c} 普通文字" showhtml="true" />

◼ CButtonUI 按钮

拥有多种状态图片的按钮。
CControlUI Label Button
属性名 类型 默认值 功能说明
normalimagestring正常状态图片
hotimagestring鼠标悬停状态图片
pushedimagestring按下状态图片
focusedimagestring获得焦点状态图片
disabledimagestring禁用状态图片
hottextcolorcolor0悬停文本颜色
pushedtextcolorcolor0按下文本颜色
focusedtextcolorcolor0焦点文本颜色
bindtablayoutnamestring绑定 TabLayout 的名称
bindtabindexint-1绑定 TabLayout 的索引
XML 示例
<Button text="点击我" width="100" height="30" 
        normalimage="btn_normal.png" hotimage="btn_hot.png" pushedimage="btn_pushed.png"
        hottextcolor="#FFFF0000" />

☑ COptionUI 选项/单选框

具有选中状态的按钮,常用于单选组或复选框。
CControlUI Label Button Option
属性名 类型 默认值 功能说明
groupstring分组名称,同组 Option 互斥(单选)
selectedboolfalse初始是否选中
selectedimagestring选中状态图片
selectedhotimagestring选中且悬停状态图片
selectedtextcolorcolor0选中状态文本颜色
XML 示例
<!-- 单选组 -->
<HorizontalLayout height="30">
    <Option name="opt1" group="g1" text="选项 A" selected="true" width="60" />
    <Option name="opt2" group="g1" text="选项 B" width="60" />
</HorizontalLayout>

<!-- 复选框 (无 group) -->
<Option name="chk1" text="复选框" width="80" selectedimage="checked.png" normalimage="unchecked.png" />

⌨ CEditUI 输入框

文本输入控件。
CControlUI Label Edit
属性名 类型 默认值 功能说明
readonlyboolfalse是否只读
passwordboolfalse是否为密码模式
passwordcharchar*密码掩码字符
maxcharint-1最大输入字符数
numberonlyboolfalse仅允许输入数字
tipvaluestring提示文本(PlaceHolder)
tipvaluecolorcolor0xFFBAC0C5提示文本颜色
nativebkcolorcolor0xFFFFFFFF原生编辑框背景色
nativetextcolorcolor0x00000000原生编辑框文本色
XML 示例
<Edit width="200" height="30" tipvalue="请输入用户名" bordercolor="#FF888888" bordersize="1" />
<Edit width="200" height="30" password="true" tipvalue="请输入密码" />

▓ CProgressUI 进度条

用于显示操作进度的控件。
CControlUI Label Progress
属性名 类型 默认值 功能说明
horbooltrue是否为水平进度条,false 为垂直
minint0进度最小值
maxint100进度最大值
valueint0当前进度值
isstretchforebooltrue是否拉伸前景图片以适应进度
XML 示例
<Progress width="200" height="20" min="0" max="100" value="50" foreimage="progress_fore.png" bkimage="progress_bg.png" />

◐ CSliderUI 滑动条

允许用户通过拖动滑块选择值的控件。
CControlUI Label Progress Slider
属性名 类型 默认值 功能说明
thumbimagestring滑块的普通状态图片
thumbhotimagestring滑块的悬停图片
thumbpushedimagestring滑块的按下状态图片
thumbsizesize10,10滑块的大小 (width,height)
stepint1步长,每次调整的增量
sendmoveboolfalse拖动时是否实时发送变化事件
XML 示例
<Slider width="200" height="20" min="0" max="100" value="30" thumbsize="15,20" thumbimage="slider_thumb.png" />

↕ CScrollBarUI 滚动条

通常由容器自动创建,但也可以独立使用。拥有非常丰富的图片属性以定制外观。
CControlUI ScrollBar
属性名 类型 默认值 功能说明
horboolfalse是否为水平滚动条
rangeint100滚动范围
valueint0当前位置
linesizeint8点击箭头的滚动步长
showbutton1booltrue是否显示第一个按钮
showbutton2booltrue是否显示第二个按钮

图片属性: 还包括 button1normalimage, button1hotimage, button1pushedimage, button2normalimage, thumbnormalimage, railnormalimage, bknormalimage 等丰富的图片属性。

XML 示例
<ScrollBar width="16" height="100" 
    button1normalimage="scrollbar_up.png" button2normalimage="scrollbar_down.png" 
    thumbnormalimage="scrollbar_bar.png" railnormalimage="scrollbar_rail.png" />

📝 CRichEditUI 富文本编辑框

支持多行、多样式文本编辑的强大控件。
CControlUI CContainerUI RichEdit
属性名 类型 默认值 功能说明
multilinebooltrue是否多行模式
readonlyboolfalse是否只读
passwordboolfalse是否密码模式
wanttabbooltrue是否接收 TAB 键输入
wantreturnbooltrue是否接收回车键换行
wantctrlreturnbooltrue是否接收 Ctrl+Enter
richbooltrue是否启用富文本特性
vscrollbarboolfalse强制显示垂直滚动条
autovscrollboolfalse自动显示垂直滚动条
tipvaluestring提示文本 (Placeholder)
XML 示例
<RichEdit width="300" height="200" multiline="true" vscrollbar="true" autovscroll="true" textcolor="#FF000000" tipvalue="请输入内容..." />

📋 CListUI 列表控件

显示垂直滚动的列表项,支持表头。
CControlUI CContainerUI CVerticalLayoutUI List
属性名 类型 默认值 功能说明
headerstringvisible表头状态,设为 hidden 可隐藏
multiselectboolfalse是否允许多选
itemfontint-1列表项默认字体
itemaltbkboolfalse是否启用隔行变色
itemselectedbkcolorcolor0xFFC1E3FF选中项背景颜色
itemhotbkcolorcolor0xFFE9F5FF悬停项背景颜色
itemshowrowlineboolfalse显示行线
itemshowcolumnlineboolfalse显示列线
XML 示例
<List width="300" height="200" itemshowrowline="true" itemshowcolumnline="true">
    <ListHeader height="24">
        <ListHeaderItem text="姓名" width="100" />
        <ListHeaderItem text="年龄" width="50" />
        <ListHeaderItem text="地址" width="150" />
    </ListHeader>
    <ListLabelElement text="张三" />
    <ListLabelElement text="李四" />
</List>

▼ CComboUI 下拉框

点击展开下拉列表供选择。
CControlUI CContainerUI Combo
属性名 类型 默认值 功能说明
dropboxstring下拉列表容器的属性列表
dropboxsizesize0,150下拉列表的大小 (width,height)
itemfontint-1下拉项字体
itemselectedbkcolorcolor0xFFC1E3FF下拉项选中背景色
itemhotbkcolorcolor0xFFE9F5FF下拉项悬停背景色
XML 示例
<Combo width="150" height="30" dropboxsize="0,100" text="请选择">
    <ListLabelElement text="选项 A" selected="true" />
    <ListLabelElement text="选项 B" />
    <ListLabelElement text="选项 C" />
</Combo>

🌳 CTreeViewUI 树形视图

用于显示层级数据的树形控件。
CControlUI CContainerUI CVerticalLayoutUI List TreeView
属性名 类型 默认值 功能说明
visiblefolderbtnbooltrue是否显示展开/折叠按钮
visiblecheckbtnboolfalse是否显示复选框
itemminwidthint0节点的最小宽度
itemtextcolorcolor0节点文本颜色
selitemtextcolorcolor0选中节点文本颜色
XML 示例
<TreeView width="200" height="300" visiblefolderbtn="true">
    <TreeNode text="根节点 1">
        <TreeNode text="子节点 1.1" />
        <TreeNode text="子节点 1.2" />
    </TreeNode>
    <TreeNode text="根节点 2">
        <TreeNode text="子节点 2.1" />
    </TreeNode>
</TreeView>

⚡ CActiveXUI ActiveX 容器

用于加载 ActiveX 控件。
CControlUI ActiveX
属性名 类型 默认值 功能说明
clsidstringActiveX 控件的 CLSID (如 {xxx-xxx...})
modulenamestring包含 ActiveX 控件的模块 (DLL) 名称
delaycreatebooltrue是否延迟创建控件
XML 示例
<ActiveX clsid="{D27CDB6E-AE6D-11CF-96B8-444553540000}" width="400" height="300" />

🌐 CWebBrowserUI IE 浏览器

封装了 IE 内核的浏览器控件。
CControlUI ActiveX WebBrowser
属性名 类型 默认值 功能说明
homepagestring初始主页 URL
autonaviboolfalse是否自动导航到主页
XML 示例
<WebBrowser homepage="https://www.baidu.com" autonavi="true" width="800" height="600" />

▶ CGifAnimUI GIF 动画

播放 GIF 动画。
CControlUI GifAnim
属性名 类型 默认值 功能说明
autoplaybooltrue是否自动播放
autosizeboolfalse是否根据图片大小自动调整控件大小
XML 示例
<GifAnim bkimage="loading.gif" autoplay="true" autosize="true" />

⌘ CHotKeyUI 热键控件

用于捕获用户键盘热键输入。
CControlUI Label HotKey
属性名 类型 默认值 功能说明
normalimagestring正常背景图
hotimagestring悬停背景图
focusedimagestring焦点背景图
disabledimagestring禁用背景图
nativebkcolorcolor0xFFFFFFFF原生热键控件背景色
XML 示例
<HotKey width="100" height="30" focusedimage="hotkey_focus.png" />

📅 CDateTimeUI 日期时间

日期时间选择控件,封装了系统的 SysDateTimePick32 窗口。
CControlUI Label DateTime

该控件主要继承 CLabelUI 属性,无特有 XML 属性,通常通过代码设置时间。

XML 示例
<DateTime width="120" height="30" textpadding="5,0,0,0" />

⚡ CFlashUI Flash 控件

专门用于播放 Flash (SWF) 的控件,继承自 CActiveXUI
CControlUI ActiveX Flash

该控件继承自 CActiveXUI,无特殊 XML 属性,核心通过加载 Flash CLSID 实现。

XML 示例
<Flash width="400" height="300" />

🎯 Duilib 全控件综合演示

AllControlsDemo.xml

这是一个包含所有主要控件的综合 XML 窗口示例。你可以直接保存为 AllControlsDemo.xml 并在 Duilib 程序中加载它来预览效果。

完整 XML 示例
<?xml version="1.0" encoding="utf-8"?>
<Window size="900,700" caption="Duilib 全控件演示窗口" mininfo="600,400" roundcorner="5,5">
    <VerticalLayout bkcolor="#FFFFFFFF" inset="15,15,15,15" childpadding="10">
        <HorizontalLayout height="40" bkcolor="#FF336699">
            <Label text="Duilib Controls Gallery" textcolor="#FFFFFFFF" font="0" align="left" valign="vcenter" />
        </HorizontalLayout>

        <HorizontalLayout childpadding="15">
            <VerticalLayout width="300" childpadding="10">
                <Label text="【基础控件】" height="20" font="1" />
                <HorizontalLayout height="30" childpadding="5">
                    <Button text="普通按钮" width="80" />
                    <Label text="普通文本标签" align="center" valign="vcenter" />
                </HorizontalLayout>
            </VerticalLayout>
        </HorizontalLayout>
    </VerticalLayout>
</Window>
为了保证预览效果,部分需要资源文件(图片/GIF)的属性被设为了默认或颜色填充,实际使用时请替换为你项目中的图片路径。