首页 > 其他 > 详细

选项与菜单函数

时间:2015-10-07 17:12:48      阅读:221      评论:0      收藏:0      [点我收藏+]

1. 清理列表框

1 winform.btnClear.oncommand = function(id,event){
2     winform.listbox.clear(); 清空
3     winform.static.text = "";
4     winform.redraw(); 刷新
5 }

2. 字符串简单格式化

1 winform.static.text =  string.format( 您选中了第%d项\n总计%d项\n项名:%s,winform.listbox.selIndex,winform.listbox.count,winform.listbox.text);
2 后面依次为参数

3.列表框添加项

1 winform.btnAdd.oncommand = function(id,event){
2     str = winform.edit.text;
3     winform.listbox.add(str)
4     winform.combobox.add(str)
5     winform.combobox.selText =  str 
6     winform.listbox.selIndex = winform.listbox.count;
7 }

4. 右键菜单

 1 //右键菜单
 2 import win.ui;
 3 import win.ui.menu; //菜单库
 4 
 5 winform.listbox.wndproc = function(hwnd,message,wParam,lParam){
 6     select( message ) { 
 7         case 0x205/*_WM_RBUTTONUP*/{
 8             var x,y = win.getMessagePos();   //获得鼠标位置
 9             var item = winform.listbox.hitTest(x,y,true); //返回屏幕坐标句柄,第三个参数表示是否是屏幕坐标
10             if( item ){
11                 winform.listbox.selIndex = item; //设置选中的索引
12                 popmenu.popup(x,y,true)  //popup弹出坐标,第三个参数如上
13             }
14         } 
15     }
16 }
17 
18 //创建弹出菜单
19 popmenu = win.ui.popmenu(winform); 
20 popmenu.add(删除,function(id){  //add(标题,回调函数)
21         winform.listbox.delete()
22 } ) 
23 
24 
25 
26 winform.show() 
27 win.loopMessage();

 5. checklist 响应

 1 //checklist响应点选
 2 import win.ui;
 3 
 4 
 5 winform.checklist.items = { "测试项目";"测试项目2";"测试项目3" }   
 6 winform.checklist.addItem("测试项目4")  
 7 winform.checklist.addItem("测试项目5")  
 8 
 9 import win.ui.menu;
10 winform.checklist.onnotify = function(id,code,ptr){  
11       if( code == 0xFFFFFF9B/*_LVN_ITEMCHANGED*/ ){ 
12           var nmListView = winform.checklist.getNotifyMessage(code,ptr);
13           if( !nmListView )
14               return;
15               
16           if( nmListView.uNewState & 0xF000/*_LVIS_STATEIMAGEMASK*/){
17               var selIndex = nmListView.iItem;
18               if( winform.checklist.getChecked( selIndex ) )
19                   winform.static.text = "选中:" + selIndex
20               else {
21                   winform.static.text = "取消选中:" + selIndex
22               } 
23           }  
24       }
25       elseif( code = 0xFFFFFFFB/*_NM_RCLICK*/ ){
26       
27           var x,y = win.getMessagePos();  
28           var nmListView = winform.checklist.getNotifyMessage(code,ptr);
29           //创建弹出菜单
30         var popmenu = win.ui.popmenu(winform); 
31         popmenu.add(删除,function(id){ 
32                 winform.checklist.delItem( nmListView.iItem )
33         } ) 
34         popmenu.popup(x,y,true);
35         popmenu.close();
36       }
37 }
38  
39 winform.show() 
40 win.loopMessage();

6. 编辑listview

 1 //编辑listview
 2 
 3 import win.ui;
 4 /*DSG{{*/
 5 var winform = ..win.form(text="aardio form";right=343;bottom=244;parent=...)
 6 winform.add(
 7 btnEdit={cls="button";text="编辑当前选中项";left=175;top=191;right=283;bottom=223;z=2};
 8 listview={cls="listview";left=25;top=23;right=310;bottom=182;bgcolor=16777215;edge=1;editable=true;z=1}
 9 )
10 /*}}*/
11 
12 //注意在上面的listview属性中,一定要指定 editable=true
13 
14 winform.listview.insertColumn("测试项",300) // 插入列,宽度300
15 winform.listview.items = {"鼠标点这里,稍候再点击一次";"鼠标单击选中项则进入编辑模式"}
16 
17 winform.btnEdit.oncommand = function(id,event){
18     winform.listview.editLable()  //点击进入编辑
19 }
20 
21 winform.listview.onnotify = function(id,code,ptr){
22      if(code = 0xFFFFFF97/*_LVN_BEGINLABELEDIT*/ ){ 
23          return false; //允许编辑项
24      }
25      if( code == 0xFFFFFF96/*_LVN_ENDLABELEDIT*/ ){
26          var dispInfo = winform.listview.getNotifyDispInfo(code,ptr); 
27          if( dispInfo ? dispInfo.item.text ) {
28             winform.listview.setItemText( dispInfo.item.text, dispInfo.item.iItem,dispInfo.item.iSubItem );
29          }
30      }
31 }
32 
33 winform.show()  
34 win.loopMessage();

 

选项与菜单函数

原文:http://www.cnblogs.com/yaoyue68/p/4858811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!