多个组件在窗口内滚动显示的示例

光庆 2023-8-1 1820

当窗口中有多个组件排列显示,一个窗口容纳不下时,需要滚动显示。

显示效果

以下为实现代码:

Code AardioLine:39复制
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
    • import win.ui;
    • /*DSG{{*/
    • var winform = win.form(text="aardio form";right=423;bottom=469)
    • winform.add(
    • custom={cls="custom";text="自定义控件";left=8;top=8;right=416;bottom=456;z=1}
    • )
    • /*}}*/
    • winform.show();
    • //批量添加组件
    • var dpi= winform.dpiScaleY
    • for(i=0;7;1){
    • var ty = dpi+i*180*dpi;
    • var th = ty + 30*dpi;
    • var py = ty + 30*dpi;
    • var ph = py + 150*dpi
    • var title = i+1++"队";
    • winform.custom.addCtrl(
    • ["title"++i+1] = {cls="plus";text=title;left=0;top=ty;right=winform.custom.width;bottom=th;align="left";bgcolor=16711808;color=16777215;font=LOGFONT(h=-16;weight=700);forecolor=255;linearGradient=45;notify=1;textPadding={left=10};z=i};
    • ["plus"++i+1] = {cls="plus";left=0;top=py;right=winform.custom.width;bottom=ph;ah=1;autohscroll=false;bgcolor=0xFFFFFFFF;autovscroll=false;aw=1;db=1;dl=1;dr=1;dt=1;notify=1;z=i}
    • )
    • }
    • var minbottom=winform.custom.height;
    • var maxbottom=winform.custom.plus8.bottom;
    • //设置滚动条范围
    • import win.ui.scrollbar;
    • var sc = win.ui.scrollbar(winform.custom,true);
    • sc.setRange(0,maxbottom - minbottom);
    • //处理滚动条超出范围后继续滚动的问题
    • winform.custom.wndproc = function(hwnd,message,wParam,lParam){
    • if message = 0x115/*_WM_VSCROLL*/ {
    • if wParam===1 {
    • if winform.custom.plus8.bottom<=minbottom return true;
    • } elseif wParam===0 {
    • if winform.custom.plus8.bottom>=maxbottom return true;
    • }
    • }
    • }
    • win.loopMessage();


    最新回复 (4)
    • tanzh 2023-8-1
      0 2

      学习了,比较高级

    • 小光芒 10月前
      0 3
      winform.custom.adjust = null 或者这样: custom={cls="custom";text="自定义控件";left=8;top=8;right=400;bottom=464;z=1;_adjustScrollBar=true} 阻止自动调整滚动条
    • breezee 10月前
      0 4

      高,实在是高!

    • zhhyit 4月前
      0 5
      思路清晰
    返回