LabelEdit,为什么设计时给LABEL.caption输入的字符,运行后不能正常显示? ( 积分: 20 )

  • 主题发起人 主题发起人 tzf19802003
  • 开始时间 开始时间
T

tzf19802003

Unregistered / Unconfirmed
GUEST, unregistred user!
TLabelAlign = (LALeft, LARight, LATop, LABottom);
TBSEdit = class(TEdit)
private
FLabelAlign : TLabelAlign;
FLabel : TLabel;
FLabelSpacing : Integer;
procedure SetLabelSpacing(const Value : Integer);
protected

procedure CMVisiblechanged(var message : TMessage);
message CM_VisibleChanged;
procedure CMEnabledchanged(var message : TMessage);
message CM_EnabledChanged;
procedure CMBiDiModechanged(var message : TMessage);
message CM_BiDiModeChanged;
procedure CM_Fontchanged(var message : TMessage);
message CM_FontChanged;
procedure SetParent(AParent : TWinControl);override;
procedure Notification(AComponent : TComponent; OPeration : TOperation);override;
public
procedure SetBounds(ALeft : Integer; ATop : Integer; AWidth : Integer; AHeight : Integer);override;
constructor create(AOwner : TComponent);override;
published
property DisplayLabel : TLabel read FLabel write FLabel;
property LabelSpacing : Integer read FLabelSpacing write SetLabelSpacing;
property LabelAlign : TLabelAlign read FLabelAlign write FLabelAlign;
end;
//----------------------------------------------------------------------------
{ TBSEdit }

procedure TBSEdit.CM_Fontchanged(var message: TMessage);
begin
inherited;
FLabel.Font := Font;
end;

procedure TBSEdit.CMBiDiModechanged(var message: TMessage);
begin
inherited;
FLabel.BiDiMode := BiDiMode;
end;

procedure TBSEdit.CMEnabledchanged(var message: TMessage);
begin
inherited;
FLabel.Enabled := Enabled;
end;

procedure TBSEdit.CMVisiblechanged(var message: TMessage);
begin
inherited;
FLabel.Visible := Visible;
end;

constructor TBSEdit.create(AOwner: TComponent);
begin
inherited;
FLabel := TLabel.Create(Self);
// FLabel.Caption := 'why?';
FLabel.FreeNotification(Self);
FLabelSpacing := DisplayLabelDefaultSpacing;
end;

procedure TBSEdit.Notification(AComponent: TComponent;
OPeration: TOperation);
begin
inherited;
// inherited Notification(AComponent, Operation);
if (OPeration = opremove) and (AComponent = FLabel) then
FLabel := nil;
end;

procedure TBSEdit.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited;
if FLabel <> nil then with FLabel do
begin
if (FLabelAlign = LALeft) then
begin
Top := ATop + (AHeight - Height) div 2;
Left := ALeft - (FLabelSpacing + Width);
end;
if (FLabelAlign = LARight) then
begin
Top := ATop + (AHeight - Height) div 2;
Left := ALeft + AWidth + FLabelSpacing;
end;
if (FLabelAlign = LATop) then
begin
Top := ATop - Height - FLabelSpacing;
Left := ALeft + (AWidth - Width) div 2;
end;
if (FLabelAlign = LABottom) then
begin
Top := ATop + AHeight + FLabelSpacing;
Left := ALeft + (AWidth - Width) div 2;
end;
end;
end;

procedure TBSEdit.SetLabelSpacing(const Value: Integer);
begin
if Value <> FLabelSpacing then
begin
FLabelSpacing := Value;
if (FLabelAlign = LALeft) then
begin
FLabel.Left := Left - (FLabelSpacing + FLabel.Width);
end;
if (FLabelAlign = LARight) then
begin
FLabel.Left := Left + Width + FLabelSpacing;
end;
if (FLabelAlign = LATop) then
begin
FLabel.Left := Left + (Width - FLabel.Width) div 2;
FLabel.Top := Top - FLabel.Height - FLabelSpacing;
end;
if (FLabelAlign = LABottom) then
begin
FLabel.Left := Left + (Width - FLabel.Width) div 2;
FLabel.Top := Top + Height + FLabelSpacing;
end;
end;
end;

procedure TBSEdit.SetParent(AParent: TWinControl);
begin
inherited;
FLabel.Parent := AParent;
end;
 
TLabelAlign = (LALeft, LARight, LATop, LABottom);
TBSEdit = class(TEdit)
private
FLabelAlign : TLabelAlign;
FLabel : TLabel;
FLabelSpacing : Integer;
procedure SetLabelSpacing(const Value : Integer);
protected

procedure CMVisiblechanged(var message : TMessage);
message CM_VisibleChanged;
procedure CMEnabledchanged(var message : TMessage);
message CM_EnabledChanged;
procedure CMBiDiModechanged(var message : TMessage);
message CM_BiDiModeChanged;
procedure CM_Fontchanged(var message : TMessage);
message CM_FontChanged;
procedure SetParent(AParent : TWinControl);override;
procedure Notification(AComponent : TComponent; OPeration : TOperation);override;
public
procedure SetBounds(ALeft : Integer; ATop : Integer; AWidth : Integer; AHeight : Integer);override;
constructor create(AOwner : TComponent);override;
published
property DisplayLabel : TLabel read FLabel write FLabel;
property LabelSpacing : Integer read FLabelSpacing write SetLabelSpacing;
property LabelAlign : TLabelAlign read FLabelAlign write FLabelAlign;
end;
//----------------------------------------------------------------------------
{ TBSEdit }

procedure TBSEdit.CM_Fontchanged(var message: TMessage);
begin
inherited;
FLabel.Font := Font;
end;

procedure TBSEdit.CMBiDiModechanged(var message: TMessage);
begin
inherited;
FLabel.BiDiMode := BiDiMode;
end;

procedure TBSEdit.CMEnabledchanged(var message: TMessage);
begin
inherited;
FLabel.Enabled := Enabled;
end;

procedure TBSEdit.CMVisiblechanged(var message: TMessage);
begin
inherited;
FLabel.Visible := Visible;
end;

constructor TBSEdit.create(AOwner: TComponent);
begin
inherited;
FLabel := TLabel.Create(Self);
// FLabel.Caption := 'why?';
FLabel.FreeNotification(Self);
FLabelSpacing := DisplayLabelDefaultSpacing;
end;

procedure TBSEdit.Notification(AComponent: TComponent;
OPeration: TOperation);
begin
inherited;
// inherited Notification(AComponent, Operation);
if (OPeration = opremove) and (AComponent = FLabel) then
FLabel := nil;
end;

procedure TBSEdit.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited;
if FLabel <> nil then with FLabel do
begin
if (FLabelAlign = LALeft) then
begin
Top := ATop + (AHeight - Height) div 2;
Left := ALeft - (FLabelSpacing + Width);
end;
if (FLabelAlign = LARight) then
begin
Top := ATop + (AHeight - Height) div 2;
Left := ALeft + AWidth + FLabelSpacing;
end;
if (FLabelAlign = LATop) then
begin
Top := ATop - Height - FLabelSpacing;
Left := ALeft + (AWidth - Width) div 2;
end;
if (FLabelAlign = LABottom) then
begin
Top := ATop + AHeight + FLabelSpacing;
Left := ALeft + (AWidth - Width) div 2;
end;
end;
end;

procedure TBSEdit.SetLabelSpacing(const Value: Integer);
begin
if Value <> FLabelSpacing then
begin
FLabelSpacing := Value;
if (FLabelAlign = LALeft) then
begin
FLabel.Left := Left - (FLabelSpacing + FLabel.Width);
end;
if (FLabelAlign = LARight) then
begin
FLabel.Left := Left + Width + FLabelSpacing;
end;
if (FLabelAlign = LATop) then
begin
FLabel.Left := Left + (Width - FLabel.Width) div 2;
FLabel.Top := Top - FLabel.Height - FLabelSpacing;
end;
if (FLabelAlign = LABottom) then
begin
FLabel.Left := Left + (Width - FLabel.Width) div 2;
FLabel.Top := Top + Height + FLabelSpacing;
end;
end;
end;

procedure TBSEdit.SetParent(AParent: TWinControl);
begin
inherited;
FLabel.Parent := AParent;
end;
 
是中文吗?字体改宋体试试?
 
如果只是想让label和edit并列或上下显示的话,最好是从tcustomcontrol上继承,
动态建立label和edit,这样就很简单了...你从edit上继承.处理显示这部分多麻烦
 
不是中文问题
只是设计时给label.caption加的文字
到了运行时看不见
怎么搞的
 
我默认给label.caption的是'123'
设计时给label.caption加的文字'456'
运行后又成'123'了
实在想不通啊?
 
这是个不难的控件开发问题啊
怎么没有朋友来呢?
 
在constructor TBSEdit.create(AOwner: TComponent);加这句:

FLabel.SetSubComponent(True); //这样才能保存包含控件的设计时信息。
 
接受答案了.
 
后退
顶部