NC Designer2实现ComboBox下拉列表功能

原始的NC Designer2没有ComboBox控件,通过TextBox与ListBox组合实现该功能

        实现原理:当ListBox控件创建时,TextBox显示ListBox的第0行的内容,当光标移动到TextBox时,ListBox设置为可访问状态,此时通过方向键选择选项,按下INPUT后把当前ListBox的内容设置到TextBox内,否则不可访问。

  • GList00001要晚于GTextBox00000创建。
    $GList00001-OnCreate
    string str ;
    GCSListAddString(-1,"GList00001","G05P1");
    GCSListAddString(-1,"GList00001","G05P2");
    GCSListAddString(-1,"GList00001","G05P10000");
    GCSListAddString(-1,"GList00001","G05P20000");
    GCSListGetListString(-1,"GList00001",0,str);
    GCSTextboxSetString(-1,"GTextBox00000",str);
    $End
  • 光标在GTextBox00000时
    $GTextBox00000-OnSetFocus
    GCSSetVisibleStatus(-1,"GList00001",1);//GList00001隐藏
    $End
  • 执行选择
    $GTextBox00064-OnKeyPress
    long _lShiftKey;
    long _lCtrlKey;
    long _lMainKey;
    _lShiftKey = LUPARAM & H1;
    _lCtrlKey = LUPARAM & H2;
    _lMainKey = LLPARAM;
    if((0 == _lCtrlKey) && (0 == _lShiftKey) && (38 == _lMainKey))
    @3 = GCSListGetCurrentSelect(-1,"GList00001");
    @4 = @3-1;
    GCSListSetCurrentSelect(-1,"GList00001",@4);
    elseif((0 == _lCtrlKey) && (0 == _lShiftKey) && (40 == _lMainKey))
    @3 = GCSListGetCurrentSelect(-1,"GList00001");
    @4 = @3+1;
    GCSListSetCurrentSelect(-1,"GList00001",@4);
    elseif((0 == _lCtrlKey) && (0 == _lShiftKey) && (13 == _lMainKey))
    GCSSetVisibleStatus(-1,"GList00001",0);
    endif;
    $End
  • 更新数据
    $GTextBox00000-OnTimer
    string str;
    GCSListGetListString(-1,"GList00001",@4,str);
    GCSTextboxSetString(-1,"GTextBox00000",str);
    $End
  • 光标离开TextBox时
    $GTextBox00000-OnKillFocus
    GCSSetVisibleStatus(-1,"GList00001",0);
    $End
posted @ 2022-07-06 16:18  PoirotArvin  阅读(253)  评论(0)    收藏  举报