delphi中为自定控件绘制windows按钮

该博客介绍了如何在Delphi中创建自定义控件,同时保持Windows样式的按钮效果。通过`defaultdraw`过程展示了如何绘制按钮,包括设置字体、颜色、边框样式,并在按钮上显示图像和文本。在不同状态下,如鼠标悬停、按下时,使用ThemeServices调整按钮的视觉效果。
摘要由CSDN通过智能技术生成
 

若要自定工具拦,但也要保留windows样式的按钮时

下面给出一种实现

procedure TmyButton.defaultdraw;
var arect,R:Trect;
    wpos,hpos:integer;
    Details: TThemedElementDetails;
begin
  hpos:=0;
  arect:=self.ClientRect;
  canvas.Font:=font;
  canvas.Brush.Color:=$CCFFFF;
  if assigned(fimagelist) then
  begin
    if (fimagelist.Count>0) or (fimage>=0) then
    begin
      wpos:=(width-imagelist.Width) div 2;
      if fhot and ( not (csDesigning in ComponentState) ) then
      begin
        R:=rect(wpos-8,0,wpos+fimagelist.width+8,fimagelist.Height+16);
        if ThemeServices.ThemesEnabled then
        begin
          if fdown then
          begin
            Details := ThemeServices.GetElementDetails(themes.ttbButtonPressed);
          end
          else
            Details :=

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值