|
本帖最后由 alajia 于 2014-4-23 16:29 编辑
用老大改进的combobox控件,实现拼音首字母动态检索汉字/数字/英文。
- import win.ui;
- /*DSG{{*/
- var winform = ..win.form(text="自动更新下拉列表";right=420;bottom=200)
- winform.add(
- combobox={cls="combobox";text="combobox";left=107;top=77;right=315;bottom=101;edge=1;items={};mode="dropdown";z=1}
- )
- /*}}*/
- var tab_items = {["测试一"]="";["测试2"]="";["测试3"]="";["其他"]="";["new"]="";["百度"]="";["谷歌Google"]="";};
- import string.conv.pinyin;
- HZtoPY = function(items){
- for(k,v in items){
- var pinyin = string.conv.pinyin(k);
- var py = "";
- for m in string.gmatch( pinyin,"\s(.{1})") {
- if(string.match(m,"\w")){
- py += m;
- }
- }
- py = pinyin[[1]] + py;
- tab_items[k] = py;
- }
- }
- HZtoPY(tab_items);
- winform.combobox.oncommand = function(id,event){
- if(event == 0x5/*_CBN_EDITCHANGE*/) {
- var items_arrar = {};
- var s = winform.combobox.text;
- for(k,v in tab_items){
- if(string.match(v,s)){
- table.push(items_arrar,k);
- }
- }
- winform.combobox.items = items_arrar //更新下拉列表
- winform.combobox.showDropDown(true);
- }
- }
- winform.combobox.wndproc = function(hwnd,message,wParam,lParam){
- if(wParam == 0xD/*_VK_RETURN*/){
- var tmp = winform.combobox.text;
- if(!tab_items[tmp]){
- win.msgbox("无效选项!","aardio");
- winform.combobox.setFocus();
- }
- }
- if(wParam == 0x1B/*_VK_ESC*/){
- winform.combobox.text = "";
- winform.combobox.setFocus();
- }
- }
- winform.combobox.setFocus();
- winform.show();
- win.loopMessage();
复制代码
|
-
|