Timage和TLable组合控件的问题?
我想用image和lable做一个图片按钮
但是lable的文字却不显示。这是为什么?
- Assembly code
constructor TImageButton.Create(AOwner: TComponent);var lb: TLabel;begin inherited Create(AOwner); FPictureDown := TPicture.Create; FPictureHot := TPicture.Create; FPictureDisable := TPicture.Create; FPictureNormal := TPicture.Create; lb := TLabel.Create(nil); lb.Width := Width; lb.Height := Height; lb.Top := Top; lb.Left := Left; lb.Parent := GetParentForm(Self); lb.Caption := 'aaaaa'; //设置了caption的,创建后却什么都没有 lb.BringToFront; Invalidate;end;
[解决办法]
如果做控件的话,不建议这样做。你应该在图片上用 drawtext 或者 textout 来输出文字。
注意处理输出文字的长度和宽度与图片的大小比较,在决定文字输出要不要断行或者省略显示之类的。