当窗口中有多个组件排列显示,一个窗口容纳不下时,需要滚动显示。
显示效果
以下为实现代码:
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();