虚表 —— 单元格内放置多个元素(按钮、图片等)演示

光庆 8天前 338

请升级vlistEx库至最新版。

import win.ui;
import godking.vlistEx;
/*DSG{{*/
winform = win.form(text="多元素演示";right=951;bottom=687;bgcolor=12639424;border="thin";mode="popup")
winform.add(
plus={cls="plus";left=696;top=16;right=920;bottom=200;color=16777215;font=LOGFONT(h=-16);foreRepeat="stretch";z=2};
plus2={cls="plus";left=704;top=208;right=928;bottom=232;color=255;font=LOGFONT(h=-16);foreRepeat="stretch";z=3};
vlist={cls="vlistEx";left=8;top=8;right=688;bottom=678;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1}
)
/*}}*/

t = {fields={"序号","多按钮演示","多图片演示"}};
for(i=1;10;1){
    var tt={};
    tt["序号"]="[@rowindex]";  // 行序号标记是不允许编辑修改的
    tt["图片"] = {
            "/4图/1.png",
            "/4图/2.png",
            "/4图/3.png",
            "/4图/4.png",
        }
    table.push(t,tt);
}
winform.vlist.setTable(t,,200,1);
winform.vlist.setRowHeight(200);
winform.vlist.textColor = 0xFF0000;
winform.vlist.setHeaderHeight(50);
winform.vlist.onDrawCellRect = function(row,col,hdc,rect,bkcolor,text,font,colalign){
    if col===2 {
        var rowh = ..math.floor(rect.height()/5);
        var rect1 = ::RECT(rect.left,rect.top,rect.right,rect.top+rowh);
        rect1.inflate(-3,-3);
        var text = {"推理提示词"+row,"文生图"+row,"图生文"+row,"超清放大"+row,"修复脸手"+row}
        for(i=1;5;1){
            ..gdi.fillRect(hdc,0xAABBCC,rect1);
            ..gdi.drawTextCenter(hdc,font,text[i],rect1);
            rect1.offset(0,rowh);
        }
        return true; 
    }
    if col===3 {
        var rowh = ..math.floor(rect.height()/2);
        var rect1 = ::RECT(rect.left,rect.top,rect.left+rowh,rect.top+rowh);
        rect1.inflate(-3,-3);
        // 绘制第1张图片
        var bmp = ..gdip.bitmap(winform.vlist.getTable()[row].图片[[1]]);
        if bmp {
            var hbmp = bmp.copyHandle();
            ..gdi.drawBitmap(hdc,hbmp,rect1,0,0,0,0);
            ::DeleteObject(hbmp);
            bmp.dispose();
        }
        // 绘制第2张图片
        rect1.offset(rowh,0)
        var bmp = ..gdip.bitmap(winform.vlist.getTable()[row].图片[[2]]);
        if bmp {
            var hbmp = bmp.copyHandle();
            ..gdi.drawBitmap(hdc,hbmp,rect1,0,0,0,0);
            ::DeleteObject(hbmp);
            bmp.dispose();
        }
        // 绘制第3张图片
        rect1.offset(-rowh,rowh);
        rect1.right += rowh;
        var bmp = ..gdip.bitmap(winform.vlist.getTable()[row].图片[[3]]);
        if bmp {
            var hbmp = bmp.copyHandle();
            ..gdi.drawBitmap(hdc,hbmp,rect1,0,0,0,0);
            ::DeleteObject(hbmp);
            bmp.dispose();
        }
        return true; 
    }
}

winform.vlist.onClick = function(row/*行*/,col/*列*/,x,y){
    if col===2 {
        var rect = winform.vlist.getCellRect(row,col);
        var rowh = ..math.floor((rect.height()-winform.vlist.padding*2)/5);
        var rect1 = ::RECT(rect.left,rect.top,rect.right,rect.top+rowh);
        rect1.inflate(-3,-3);
        var text = {"推理提示词"+row,"文生图"+row,"图生文"+row,"超清放大"+row,"修复脸手"+row};
        for(i=1;5;1){
            if ::PtInRect(rect1,x,y) {
                ..win.msgbox("您点击了第"++row++"行第"++i++"个按钮:"++text[i],"提示");
                return ; 
            }
            rect1.offset(0,rowh);
        }
       } elseif col===3 { 
        var rect = winform.vlist.getCellRect(row,col);
        var rowh = ..math.floor((rect.height()-winform.vlist.padding*2)/2);
        var rect1 = ::RECT(rect.left,rect.top,rect.left+rowh,rect.top+rowh);        
        //判断是否点了第1张图片
        rect1.inflate(-3,-3);
        if ::PtInRect(rect1,x,y) {
            winform.plus.foreground = winform.vlist.getTable()[row].图片[[1]];
            winform.plus2.text = "第"++row++"行,第1张图片"
            return ;
        } 
        //判断是否点了第2张图片
        rect1.offset(rowh,0)
        if ::PtInRect(rect1,x,y) {
            winform.plus.foreground = winform.vlist.getTable()[row].图片[[2]];
            winform.plus2.text = "第"++row++"行,第2张图片"
            return ;
        } 
        //判断是否点了第3张图片
        rect1.offset(-rowh,rowh);
        rect1.right += rowh;
        if ::PtInRect(rect1,x,y) {
            winform.plus.foreground = winform.vlist.getTable()[row].图片[[3]];
            winform.plus2.text = "第"++row++"行,第3张图片"
            return ;
        } 
    }
}

winform.show();
win.loopMessage();

使用 @ownerDrawImg 图片配合 godking.paint 库,可非常方便的绘制带透明度的png图片。

import win.ui;
import godking.vlistEx;
/*DSG{{*/
winform = win.form(text="多元素演示";right=951;bottom=687;bgcolor=12639424;border="thin";mode="popup")
winform.add(
plus={cls="plus";left=696;top=16;right=920;bottom=200;color=16777215;font=LOGFONT(h=-16);foreRepeat="stretch";z=2};
plus2={cls="plus";left=704;top=208;right=928;bottom=232;color=255;font=LOGFONT(h=-16);foreRepeat="stretch";z=3};
vlist={cls="vlistEx";left=8;top=8;right=688;bottom=678;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1}
)
/*}}*/

t = {fields={"序号","多按钮演示","多图片演示"}};
for(i=1;10;1){
    var tt={};
    tt["序号"]="[@rowindex]";  // 行序号标记是不允许编辑修改的
    tt["多图片演示"] = "<img name='@ownerDrawImg',full=true>"
    tt["图片"] = {
        "/4图/1.png",
        "/4图/2.png",
        "/4图/3.png",
        "/4图/4.png",
    }
    table.push(t,tt);
}
winform.vlist.setTable(t,,200,1);
winform.vlist.setRowHeight(200);
winform.vlist.textColor = 0xFF0000;
winform.vlist.setHeaderHeight(50);

import godking.paint;
winform.vlist.ownerDrawImg = function (row,col,hdc,x,y,w,h,param){
   if col===3 {
   		// 使用 @ownerDrawImg 图片配合 godking.paint 库,可非常方便的绘制带透明度的png图片。
   		var rect = ::RECT(x,y,x+w,y+h);
        var rowh = ..math.floor(rect.height()/2);
        var rect1 = ::RECT(rect.left,rect.top,rect.left+rowh,rect.top+rowh);
        rect1.inflate(-3,-3);
        // 绘制第1张图片
        var  p = godking.paint.fromHdc(hdc);
        p.drawImage(rect1,winform.vlist.getTable()[row].图片[[1]]/*图片*/,/*透明度或图片属性*/,/*保持比例*/)
        // 绘制第2张图片
        rect1.offset(rowh,0)
        p.drawImage(rect1,winform.vlist.getTable()[row].图片[[2]]/*图片*/,/*透明度或图片属性*/,/*保持比例*/)
        // 绘制第3张图片
        rect1.offset(-rowh,rowh);
        rect1.right += rowh;
        p.drawImage(rect1,winform.vlist.getTable()[row].图片[[3]]/*图片*/,/*透明度或图片属性*/,/*保持比例*/)               
        p.close();
    }    
}

winform.show();
win.loopMessage();

或这样:

winform.vlist.ownerDrawImg = function (row,col,hdc,x,y,w,h,param){
   if col===3 {
   		// 使用 @ownerDrawImg 图片配合 godking.paint 库,可非常方便的绘制带透明度的png图片。
        var rowh = ..math.floor(h/2);
        var x,y,w,h = x+3,y+3,rowh-6,rowh-6;
        // 绘制第1张图片
        var  p = godking.paint.fromHdc(hdc);
        p.drawImageF(x,y,w,h,owner.getTable()[row].图片[[1]]/*图片*/,/*透明度或图片属性*/,/*保持比例*/)
        // 绘制第2张图片
        x += rowh;
        p.drawImageF(x,y,w,h,owner.getTable()[row].图片[[2]]/*图片*/,/*透明度或图片属性*/,/*保持比例*/)
        // 绘制第3张图片
        x -= rowh;
        y += rowh;
        w += rowh;
        p.drawImageF(x,y,w,h,owner.getTable()[row].图片[[3]]/*图片*/,/*透明度或图片属性*/,/*保持比例*/)
        p.close();
    }    
}


上传的附件:
最新回复 (1)
  • netfox 7天前
    0 引用 2

    顶到G点,顶点肺

          ◣◢       ◣◢ 
      \ ●  ● / 
      -≡◢████◣≡- 
      -≡██████≡- 
     /◥████◤\       
      ∪       ∪..............凡走过,必留下我的足迹。 

    ---看贴要回帖,回帖满15字,aardio加油--------

返回