|
本帖最后由 popdes 于 2018-8-5 15:32 编辑
看到网上有好多对combobox控件进行各种自绘的,但是代码写下来,感觉这么麻烦的改造,还不如直接用htmlayout来的方便灵活.....
效果如下:
代码如下:
- import win.ui;
- /*DSG{{*/
- var winform = win.form(text="combobox控件自绘演示";right=255;bottom=104)
- winform.add(
- combobox={cls="combobox";left=62;top=30;right=206;bottom=56;color=255;edge=1;items={"10";"13";"25";"50";"36";"70"};mode="dropdownlist";ownerDraw=1;vscroll=1;style=0x20/*_CBS_OWNERDRAWVARIABLE*/|0x200/*_CBS_HASSTRINGS*/;z=1}
- )
- /*}}*/
- import win.graphics;
- winform.combobox.onDrawItem = function(drawItem){
- var cvs = win.graphics.canvas(); // 创建一个画布
- cvs.fromHDC(drawItem.hDC); // 传入 hDC
- //奇偶行
- if(drawItem.itemID%2!=0){
- cvs.brush.color = 0x00c044; // 定义刷子颜色
- }
- else {
- cvs.brush.color = 0xffffff;
- }
- //当时是想改变这个RC大小的,也可以舍弃不用
- var rc = ::RECT(drawItem.rcItem.left,drawItem.rcItem.top,drawItem.rcItem.right,drawItem.rcItem.bottom);
-
- cvs.fillRect(rc);
- cvs.pen.color = 0x000000;
- //只画底部线条
- cvs.drawEdge(rc, 0x8/*_BF_BOTTOM*/);
- //焦点处理
- if(drawItem.itemState&1/*_ODS_SELECTED*/){
- cvs.font.color = 0x0000ff;
- cvs.textOut(rc.left+20, rc.top, winform.combobox.items[drawItem.itemID+1])
- cvs.drawFocusRect(rc);
- }else {
- cvs.pen.color = 0xff8057; // 定义画笔的颜色
- cvs.textOut(rc.left+20, rc.top, winform.combobox.items[drawItem.itemID+1]);
- }
- cvs.destroy();
- }
- winform.show()
- win.loopMessage();
复制代码 |
|