3DLabel控件

翻译|其它|编辑:郝浩|2005-06-17 10:02:00.000|阅读 1679 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>


 
3DLabel控件

程序代码如下所示:

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.

 


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP