【第八章8.2】 窗口控件 -- listbox列表框控件 的编辑
控件位置:
代码:
// 导入 win.ui 库,用于创建图形界面 import win.ui; /*DSG{{*/ // 创建一个名为 winform 的窗口对象,并设置其相关属性 var winform = win.form(text="aardio form";right=349;bottom=249;parent=...) // 向窗口中添加一个列表框控件,并设置其属性和项目 winform.add( listbox={cls="listbox";left=75;top=36;right=284;bottom=192;bgcolor=16777215;edge=1;items={"ddddddddddd";"cccc";"双击编辑"};z=1} ) /*}}*/ // 为列表框添加一个编辑控件,并设置其相关属性和窗口过程函数 var lstEdit = winform.listbox.addCtrl( edit = { cls="edit"; // 编辑控件的类名 left=0;top=0;right=50;bottom=50; // 编辑控件的位置和大小 autoResize=false ; // 编辑控件不自动调整大小 hide=1; // 编辑控件初始隐藏 edge=1; // 编辑控件的边框样式 wndproc = function(hwnd,message,wparam,lparam){ // 编辑控件的窗口过程函数 if( message == 0x8/*_WM_KILLFOCUS*/ // 当失去焦点 || (message==0x101/*_WM_KEYUP*/ && wparam == 0xD/*_VK_ENTER*/) ) { // 或者按下回车键 if( owner.selIndex){ // 如果有选中项 winform.listbox.add(owner.text,owner.selIndex) // 在列表框中添加文本 winform.listbox.delete(owner.selIndex+1) // 删除下一项 owner.hide = true; // 隐藏编辑控件 winform.listbox.redraw() // 重绘列表框 } } }; } ).edit // 为列表框添加双击事件处理函数 winform.listbox.oncommand = function(id,event){ if( event == 0x2/*_LBN_DBLCLK*/ ){ // 当发生双击事件 var rc = owner.getItemRect( owner.selIndex ) // 获取选中项的矩形区域 rc.bottom += 5; // 调整矩形区域的底部位置 lstEdit.setRect(rc) // 设置编辑控件的矩形区域 lstEdit.hide = false; // 显示编辑控件 lstEdit.text = winform.listbox.selText; // 设置编辑控件的文本为选中项的文本 lstEdit.selIndex = owner.selIndex ; // 设置编辑控件的选中索引 } } // 显示窗口 winform.show() // 启动界面线程消息循环 win.loopMessage();
运行效果图:
相关回复
-
暂无评论!