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;
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;