【发布时间】:2011-10-13 22:55:48
【问题描述】:
我创建了一个继承自 TCornerButton 的新组件以添加下拉菜单选项。
第一个问题...
为什么我需要重写“AfterPaint”方法而不是文档中描述的“Paint”方法。覆盖“Paint”并没有产生任何绘图。
第二个问题...
当我使用“AfterPaint”方法绘制一个小向下箭头时,它的偏移量大约为 5 个像素,直到按钮获得焦点。只是将鼠标悬停在按钮上似乎并不能解决问题(因为您希望会发生重绘)。我已经将它与代码中的“ScalePoint”联系起来,并且每次都是错误的。 它还在设计时显示在错误的位置。一旦按钮在运行时获得焦点,箭头就会移动到预期位置。当它失去焦点时,它会回到错误的位置。 供参考。 “宽度”没有改变 - 我已经对此进行了测试。
procedure TLFButton.AfterPaint;
var
down_arrow: TPolygon;
x, y: Extended;
begin
inherited;
if FDropDownButton then
begin
Canvas.Fill := TText(FindStyleResource('text')).Fill;
x := Width - 12;
y := (Height / 2) - 3;
SetLength(down_arrow, 3);
down_arrow[0] := ScalePoint(PointF(x, y), Scale.X, Scale.Y);
down_arrow[1] := ScalePoint(PointF(x+8,y), Scale.X, Scale.Y);
down_arrow[2] := ScalePoint(PointF(x+4,y+6), Scale.X, Scale.Y);
Canvas.FillPolygon(down_arrow, 255);
end;
end;
【问题讨论】:
标签: delphi delphi-xe2 firemonkey