设置自定义控件的默认属性
我编写了一个源自 TCustomEdit 的控件,但在更改 StdCtrls 中定义的组件的默认大小(即宽度=121,高度=21)时遇到问题。
所以在 Create 中我有:
inherited Create(AOwner);
width:=40;
height:=20;
但是当控件放置在窗体上时,它会使用 TCustomEdit 的默认宽度和高度进行绘制。我已将测试用例简化为一个简单的组件,仅具有上面的构造函数而没有其他内容。我也尝试在构造函数中设置 autosize:=false
但没有任何乐趣。
通过四处寻找,我认为我正在做正确的事情,但显然它不起作用。如何获得我想要的行为?
I've written a control descended from TCustomEdit but am having trouble changing the default size of the component from that defined in StdCtrls (i.e. width=121, height=21).
So in Create I have:
inherited Create(AOwner);
width:=40;
height:=20;
But when the control is placed on the form it is drawn with the default width and height for TCustomEdit. I've reduced the test case to a simple component that merely has the constructor above and nothing else. I've also tried setting autosize:=false
in the constructor but no joy.
From searching around I think I'm doing the right thing but plainly it's not working. How to I get the behaviour I'm after?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用(XE2)。确保您的构造函数被标记为
override
,以便实际调用它:这是必要的,因为
TComponent
有一个虚拟构造函数。That works for me (XE2). Make sure your constructor is marked
override
so that it is actually called:This is necessary because
TComponent
has a virtual constructor.