TImage不会与父对象对齐 [英] TImage won't align to parent
本文介绍了TImage不会与父对象对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个包含TImage32的自定义TPanel。
除非我手动调整父控件的大小,否则图像将不会与父控件对齐。之后,它将保持良好对齐。
为什么?
I want to create a custom TPanel that has a TImage32 in it.
The image won't align to the parent until I manually resize the parent control. After that it will stay nicely aligned.
Why?
TYPE
TDisplay1= class(TPanel)
private
Ready: Boolean;
RightPnl : TPanel;
ShowA : TSpeedButton;
Display : TImage32;
protected
procedure Resize; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
IMPLEMENTATION
procedure TDisplay1.Resize; <-------- the culprit was here as suggested by Vahid
begin
inherited;
if Ready
then Display.SetupBitmap(TRUE, clYellow32);
end;
更新:
我正在使用一种可替代的方式来加载解决方案控制。我会告诉你我是否成功。
Update:
I am working o a solution with an alternative way to load the control. I will let you know if I succeed.
Update2:
Vahid的回答更好。谢谢Vahid。
Update2:
Vahid answer's was better. Thanks Vahid.
推荐答案
将此代码添加到面板中:
Add this code to your panel:
...
protected
procedure Paint; override;
...
procedure TDisplay1.Paint;
begin
inherited;
if Ready then Display.SetupBitmap(TRUE, clYellow32);
end;
这篇关于TImage不会与父对象对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文