unit JvDBLabeledEdit; interface uses Windows, Messages, SysUtils, Classes, Controls, StdCtrls, ExtCtrls, Mask, DBCtrls; type TJvBoundLabel = class(TBoundLabel) published property Autosize; property Alignment; end; TJvCustomDBLabeledEdit = class(TDBEdit) private FEditLabel: TJvBoundLabel; FLabelPosition: TLabelPosition; FLabelSpacing: Integer; procedure SetLabelPosition(const Value: TLabelPosition); procedure SetLabelSpacing(const Value: Integer); protected procedure SetParent(AParent: TWinControl); override; procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure SetName(const Value: TComponentName); override; procedure CMVisiblechanged(var Message: TMessage); message CM_VISIBLECHANGED; procedure CMEnabledchanged(var Message: TMessage); message CM_ENABLEDCHANGED; procedure CMBidimodechanged(var Message: TMessage); message CM_BIDIMODECHANGED; public { Public declarations } constructor Create(AOwner: TComponent); override; procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override; procedure SetupInternalLabel; property EditLabel: TJvBoundLabel read FEditLabel; property LabelPosition: TLabelPosition read FLabelPosition write SetLabelPosition; property LabelSpacing: Integer read FLabelSpacing write SetLabelSpacing; end; TJvDBLabeledEdit = class(TJvCustomDBLabeledEdit) published property Anchors; property AutoSelect; property AutoSize; property BevelEdges; property BevelInner; property BevelKind; property BevelOuter; property BiDiMode; property BorderStyle; property CharCase; property Color; property Constraints; property Ctl3D; property DragCursor; property DragKind; property DragMode; property EditLabel; property Enabled; property Font; property ImeMode; property ImeName; property LabelPosition; property LabelSpacing; property MaxLength; property OEMConvert; property ParentBiDiMode; property ParentColor; property ParentCtl3D; property ParentFont; property ParentShowHint; property PasswordChar; property PopupMenu; property ReadOnly; property ShowHint; property TabOrder; property TabStop; property Visible; property OnChange; property OnClick; property OnContextPopup; property OnDblClick; property OnDragDrop; property OnDragOver; property OnEndDock; property OnEndDrag; property OnEnter; property OnExit; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnMouseDown; property OnMouseMove; property OnMouseUp; property OnStartDock; property OnStartDrag; end; implementation { TJvCustomDBLabeledEdit } constructor TJvCustomDBLabeledEdit.Create(AOwner: TComponent); begin inherited Create(AOwner); FLabelPosition := lpAbove; FLabelSpacing := 3; SetupInternalLabel; end; procedure TJvCustomDBLabeledEdit.CMBidimodechanged(var Message: TMessage); begin inherited; FEditLabel.BiDiMode := BiDiMode; end; procedure TJvCustomDBLabeledEdit.CMEnabledchanged(var Message: TMessage); begin inherited; FEditLabel.Enabled := Enabled; end; procedure TJvCustomDBLabeledEdit.CMVisiblechanged(var Message: TMessage); begin inherited; FEditLabel.Visible := Visible; end; procedure TJvCustomDBLabeledEdit.Notification(AComponent: TComponent; Operation: TOperation); begin inherited Notification(AComponent, Operation); if (AComponent = FEditLabel) and (Operation = opRemove) then FEditLabel := nil; end; procedure TJvCustomDBLabeledEdit.SetBounds(ALeft, ATop, AWidth, AHeight: Integer); begin inherited SetBounds(ALeft, ATop, AWidth, AHeight); SetLabelPosition(FLabelPosition); end; procedure TJvCustomDBLabeledEdit.SetLabelPosition(const Value: TLabelPosition); var P: TPoint; begin if FEditLabel = nil then exit; FLabelPosition := Value; case Value of lpAbove: P := Point(Left, Top - FEditLabel.Height - FLabelSpacing); lpBelow: P := Point(Left, Top + Height + FLabelSpacing); lpLeft : P := Point(Left - FEditLabel.Width - FLabelSpacing, Top + ((Height - FEditLabel.Height) div 2)); lpRight: P := Point(Left + Width + FLabelSpacing, Top + ((Height - FEditLabel.Height) div 2)); end; FEditLabel.SetBounds(P.x, P.y, FEditLabel.Width, FEditLabel.Height); end; procedure TJvCustomDBLabeledEdit.SetLabelSpacing(const Value: Integer); begin FLabelSpacing := Value; SetLabelPosition(FLabelPosition); end; procedure TJvCustomDBLabeledEdit.SetName(const Value: TComponentName); begin if (csDesigning in ComponentState) and ((FEditlabel.GetTextLen = 0) or (CompareText(FEditLabel.Caption, Name) = 0)) then FEditLabel.Caption := Value; inherited SetName(Value); if csDesigning in ComponentState then Text := ''; end; procedure TJvCustomDBLabeledEdit.SetParent(AParent: TWinControl); begin inherited SetParent(AParent); if FEditLabel = nil then exit; FEditLabel.Parent := AParent; FEditLabel.Visible := True; FEditLabel.AutoSize := false; end; procedure TJvCustomDBLabeledEdit.SetupInternalLabel; begin if Assigned(FEditLabel) then exit; FEditLabel := TJvBoundLabel.Create(Self); FEditLabel.FreeNotification(Self); end; end.