我最近开始将应用程序转换为FireMonkey,并从简单的控件开始。出于某种原因,与TPanel或TButton等表格上的掉落组件相比,他们的位置是不对的。从我的测试来看,这个位置看起来翻了一倍。
我的测试项目很简单:(在Delphi XE5中)
代码:
type
TTest = class(TPaintBox)
private
FBitmap: TBitmap;
public
Constructor Create(AOwner:TComponent); override;
Destructor Destroy; override;
procedure Paint; override;
end;
{ TTest }
constructor TTest.Create(AOwner: TComponent);
begin
inherited;
FBitmap := TBitmap.Create;
FBitmap.LoadFromFile('c:\test.png');
Width := FBitmap.Width;
Height := FBitmap.Height;
end;
destructor TTest.Destroy;
begin
FreeAndNil(FBitmap);
inherited;
end;
procedure TTest.Paint;
begin
Canvas.DrawBitmap(FBitmap,
TRectf.Create(0, 0, FBitmap.Width, FBitmap.Height),
AbsoluteRect,
1);
end;
代码:
procedure TForm2.FormCreate(Sender: TObject);
var t: TTest;
begin
t := TTest.Create(self);
t.Parent := self;
t.Position.X := 50;
t.Position.Y := 50;
end;
为Win32构建它。
在我的结尾,图像出现在面板的左上角,这是100,100,但控件显然设置为50,50
调试显示位置和位置的正确值。
我无法弄清楚发生了什么。也许有人有一些建议/解释。
感谢。
答案 0 :(得分:3)
AbsoluteRect是控件相对于它的Form的矩形。如果你想画一些东西你必须使用本地坐标,在这种情况下LocalRect。
Canvas.DrawBitmap(FBitmap, TRectf.Create(0, 0, FBitmap.Width, FBitmap.Height), LocalRect, 1);