首页 | 社区 | 博客 | 招聘 | 文章 | 新闻 | 下载 | 读书 | 代码
亲,您未登录哦! 登录 | 注册

3DLabel控件

打印文章

分享到:
unit IDSLabel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  ExtCtrls;

type
  TIDSLabel = class(TBevel)
  private
    { Private declarations }
    FAlignment : TAlignment;
    FCaption : String;
    FFont : TFont;
    FOffset : Byte;

    FOnChange : TNotifyEvent;

    procedure SetAlignment( taIn : TAlignment );
    procedure SetCaption( const strIn : String);
    procedure SetFont( fntNew : TFont );
    procedure SetOffset( bOffNew : Byte );
  protected
    { Protected declarations }
    constructor Create( compOwn : TComponent ); override;
    destructor Destroy; override;
    procedure Paint; override;
  public
    { Public declarations }
  published
    { Published declarations }
    property Alignment : TAlignment read FAlignment write SetAlignment default  
taLeftJustify;
    property Caption : String read FCaption write SetCaption;
    property Font : TFont read FFont write SetFont;
    property Offset : Byte read FOffset write SetOffset;

    property OnChange : TNotifyEvent read FOnChange write FOnChange;
  end;

implementation

constructor TIDSLabel.Create;
begin
   inherited Create(compOwn);

   FFont := TFont.Create;
   with compOwn as TForm do
       FFont.Assign(Font);

   Offset := 4;
   Height := 15;
end;

destructor TIDSLabel.Destroy;
begin
   FFont.Free;

   inherited Destroy;
end;

procedure TIDSLabel.Paint;
var
   wXPos, wYPos : Word;
begin

   {Draw the bevel}
   inherited Paint;

   {Retreive the font}
   Canvas.Font.Assign(Font);

   {Calculate the y position}
   wYPos := (Height - Canvas.TextHeight(Caption)) div 2;

   {Calculate the x position}
   wXPos := Offset;
   case Alignment of
       taRightJustify: wXPos := Width - Canvas.TextWidth(Caption) - Offset;
       taCenter:       wXPos := (Width - Canvas.TextWidth(Caption)) div 2;
   end;
   Canvas.Brush := Parent.Brush;
   Canvas.TextOut(wXPos,wYPos,Caption);

end;

procedure TIDSLabel.SetAlignment;
begin
   FAlignment := taIn;
   Invalidate;
end;

procedure TIDSLabel.SetCaption;
begin
   FCaption := strIn;

   if Assigned(FOnChange) then
       FOnChange(Self);

   Invalidate;
end;

procedure TIDSLabel.SetFont;
begin
   FFont.Assign(fntNew);
   Invalidate;
end;

procedure TIDSLabel.SetOffset;
begin
   FOffset := bOffNew;
   Invalidate;
end;

end. 

本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )

编程爱好者论坛

本栏最新文章