【第十章 10.2】列表框控件Listbox -- 控件演示
界面演示:
代码:
// 导入 win.ui 库,用于创建图形界面 import win.ui; /*DSG{{*/ // 创建一个名为 winform 的窗口对象,并设置其属性 var winform = win.form(text="button/listbox/edit控件演示";right=397;bottom=171) // 向窗口中添加控件 winform.add( // 添加"添加"按钮控件,并设置其属性 btnAdd={cls="button";text="添加";left=126;top=51;right=172;bottom=75;z=4}; // 添加"清除"按钮控件,并设置其属性 btnClear={cls="button";text="清除";left=184;top=52;right=230;bottom=76;z=3}; // 添加"删除"按钮控件,并设置其属性 btnDelete={cls="button";text="删除";left=241;top=52;right=287;bottom=76;z=2}; // 添加"模糊查找"按钮控件,并设置其属性 btnFind={cls="button";text="模糊查找";left=297;top=52;right=360;bottom=76;z=10}; // 添加"精确查找"按钮控件,并设置其属性 btnFindEx={cls="button";text="精确查找";left=298;top=83;right=362;bottom=107;z=11}; // 添加组合框控件,并设置其属性 combobox={cls="combobox";left=128;top=81;right=236;bottom=101;edge=1;items={};mode="dropdown";z=8}; // 添加编辑框控件,并设置其属性 edit={cls="edit";text="请输入...";left=129;top=20;right=360;bottom=44;acceptfiles=1;edge=1;multiline=1;tabstop=1;z=9}; // 添加分组框控件,并设置其属性 groupbox={cls="groupbox";text="添加删除";left=114;top=2;right=379;bottom=165;acceptfiles=1;edge=1;tabstop=1;z=1}; // 添加列表框控件,并设置其属性 listbox={cls="listbox";left=3;top=3;right=110;bottom=144;acceptfiles=1;bgcolor=16777215;edge=1;items={};tabstop=1;vscroll=1;z=6}; // 添加静态文本控件,并设置其属性 static={cls="static";left=128;top=111;right=360;bottom=158;acceptfiles=1;edge=1;tabstop=1;transparent=1;z=5}; // 添加另一个静态文本控件,并设置其属性 static2={cls="static";text="static2";left=196;top=235;right=197;bottom=236;acceptfiles=1;bgcolor=14215660;tabstop=1;transparent=1;z=7} ) /*}}*/ // "精确查找"按钮的命令事件处理函数 winform.btnFindEx.oncommand = function(id,event){ // 在列表框中精确查找编辑框中的文本,并获取索引 var ind = winform.listbox.findEx(winform.edit.text); // 设置列表框的选中索引 winform.listbox.selIndex = ind; // 弹出消息框显示索引 win.msgbox(ind,"aardio"); } // "模糊查找"按钮的命令事件处理函数 winform.btnFind.oncommand = function(id,event){ // 在列表框中模糊查找编辑框中的文本,并获取索引 var ind = winform.listbox.find(winform.edit.text) // 设置列表框的选中索引 winform.listbox.selIndex = ind } // 组合框的命令事件处理函数 winform.combobox.oncommand = function(id,event){ // 当组合框的选择发生改变时 if(event == 0x1/*_CBN_SELCHANGE*/){ // 将组合框的选中文本设置到编辑框中 winform.edit.text = winform.combobox.selText; } } // "清除"按钮的命令事件处理函数 winform.btnClear.oncommand = function(id,event){ // 清空列表框 winform.listbox.clear(); // 清空静态文本控件的文本 winform.static.text = ""; // 重绘窗口 winform.redraw(); } // 列表框的命令事件处理函数 winform.listbox.oncommand = function(id,event){ // 当列表框的选择发生改变时 if( event == 0x1/*_LBN_SELCHANGE*/ ){ // 格式化并设置静态文本控件的文本,显示选中项的相关信息 winform.static.text = string.format( '您选中了第%d项\n总计%d项\n项文本:%s' ,winform.listbox.selIndex ,winform.listbox.count ,winform.listbox.selText ); } } // "删除"按钮的命令事件处理函数 winform.btnDelete.oncommand = function(id,event){ // 删除列表框中的选中项 winform.listbox.delete(); } // "添加"按钮的命令事件处理函数 winform.btnAdd.oncommand = function(id,event){ // 获取编辑框中的文本 str = winform.edit.text; // 向列表框中添加文本 winform.listbox.add(str); // 向组合框中添加文本 winform.combobox.add(str); // 设置组合框的选中文本 winform.combobox.selText = str; // 设置列表框的选中索引为最后一项 winform.listbox.selIndex = winform.listbox.count; } // 显示窗口 winform.show(true); // 启动窗口的消息循环 win.loopMessage( winform );
相关回复
-
暂无评论!