TSpeedButton是不支持自绘的,即使为它创建一个TControlCanvas,画上去的图也保持不了。
于是想到了SpeedButton的Glyph属性。
不错,Glyphi装的可不是TBitmap么?直接画它不就得了。
赶紧Test一下,果然,OK。
以下是测试代码:
procedure TForm1.Button1Click(Sender: TObject);
var
bmp:TBitmap;
begin
bmp:=TBitmap.Create;
bmp.Assign(bt1.Glyph);
bt1.Glyph := nil;
with bmp.Canvas do
begin
Brush.Color:=clRed;
Brush.Style := bsSolid;
FillRect(Rect(2,12,14,16));
end;
bmp.Free;
end;
本文介绍了一种在Delphi中使用SpeedButton的自绘方法。由于SpeedButton本身不支持自绘,作者通过利用SpeedButton的Glyph属性来实现自定义绘制。具体实现方式是将绘制的内容赋值给TBitmap,然后清空SpeedButton的Glyph属性,并在TBitmap上进行自绘操作。
181

被折叠的 条评论
为什么被折叠?



