修改XPMenu让ToolButton在Down=True时正确显示
[入库:2005年8月18日] [更新:2007年3月24日]
xpmenu是一个不错的程序界面效果控件,但它也存在不少不足之处。我最近又对它作了一点修改。
原因是我在程序里有一个toolbutton,其style=tbsbutton,当down=true时,xpmenu绘制的效果效果跟down=false时一样,也就是说根本看不出它是按下的。当把style改为tbscheck后,却能显示效果,但是底色很深。
这个按钮来我是用来表示某个面板是否可以显示的,我希望它像officexp的工具按钮那样,当工具条显示时,在按钮上画个边框即可,而不是以很深的底色显示。
xpmenu绘制工具栏按钮是由txpmenu.toolbardrawbutton函数完成,原型为如下:
| procedure txpmenu.toolbardrawbutton(sender: ttoolbar; button: ttoolbutton; state: tcustomdrawstate; var defaultdraw: boolean); |
在函数内由以下代码决定按钮是否显示边框,以及用什么颜色作底色:
if (cdshot in state) then begin if (cdschecked in state) or (button.down) or (cdsselected in state) then acanvas.brush.color := fcheckedareaselectcolor else acanvas.brush.color := fbselectcolor; hasborder := true; hasbkg := true; end; if ((cdschecked in state) and not (cdshot in state)) then begin acanvas.brush.color := fcheckedareacolor; hasborder := true; hasbkg := true; end; if (cdsindeterminate in state) and not (cdshot in state) then begin acanvas.brush.color := fbselectcolor; hasbkg := true; end; |
它忽略掉了非cdshot、非cdschecked状态下按钮的down=true的情况的处理。因此只要加上相应的判断,并让hasborder=true即可达到我希望的效果。修改后代码如下:
if (cdshot in state) then begin if (cdschecked in state) or (button.down) or (cdsselected in state) then acanvas.brush.color := fcheckedareaselectcolor else acanvas.brush.color := fbselectcolor; hasborder := true; hasbkg := true; end; if ((cdschecked in state) and not (cdshot in state)) then begin acanvas.brush.color := fcheckedareacolor; hasborder := true; hasbkg := true; end; {modify: conch 2005-3-10 在down=true的按钮上画出边框} if (button.down) and not (cdshot in state) then begin hasborder := true; hasbkg := false; end; //conch if (cdsindeterminate in state) and not (cdshot in state) then begin acanvas.brush.color := fbselectcolor; hasbkg := true; end; |
本文关键:修改XPMenu让ToolButton在Down=True时正确显示
本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)