FLabel.cpp
上传用户:hnxhmj
上传日期:2020-10-13
资源大小:14k
文件大小:3k
源码类别:

Static控件

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "FLabel.h"
  5. #pragma package(smart_init)
  6. //---------------------------------------------------------------------------
  7. // ValidCtrCheck is used to assure that the components created do not have
  8. // any pure virtual functions.
  9. //
  10. static inline void ValidCtrCheck(TFLabel *)
  11. {
  12.         new TFLabel(NULL);
  13. }
  14. //---------------------------------------------------------------------------
  15. __fastcall TFLabel::TFLabel(TComponent* Owner)
  16.         : TLabel(Owner)
  17. {
  18. }
  19. //---------------------------------------------------------------------------
  20. namespace Flabel
  21. {
  22.         void __fastcall PACKAGE Register()
  23.         {
  24.                  TComponentClass classes[1] = {__classid(TFLabel)};
  25.                  RegisterComponents("Custom", classes, 0);
  26.         }
  27. }
  28. //---------------------------------------------------------------------------
  29. void __fastcall TFLabel::SetTextSpace(int Value)
  30. {
  31.    if(FTextSpace!=Value)
  32.    {
  33.         //int Diff=Value-FTextSpace;
  34.         FTextSpace=Value;
  35.         //int len=(WideString(Caption)).Length()-1;
  36.         //if(len) Width+=len*Diff;//加上TextSpace
  37.         Width++;
  38.         Width--;
  39.         //AdjustBounds();
  40.    }
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TFLabel::DoDrawText(TRect &Rect, int Flags)
  44. {
  45.     AnsiString Text;
  46.     Text = GetLabelText();
  47.     if( (Flags && DT_CALCRECT!=0) && ((Text == "") || ( ShowAccelChar && Text.c_str()[0] == '&' && Text.c_str()[1] == '')))
  48.         Text = Text + " ";
  49.     if(!ShowAccelChar) Flags = Flags | DT_NOPREFIX;
  50.     Flags = DrawTextBiDiModeFlags(Flags);
  51.     Canvas->Font = Font;
  52.     SetTextCharacterExtra(Canvas->Handle,TextSpace);  //设置字符间距;
  53.     if(!Enabled)
  54.     {
  55.         OffsetRect(&Rect, 1, 1);
  56.         Canvas->Font->Color = clBtnHighlight;
  57.         DrawText(Canvas->Handle, Text.c_str(), Text.Length(), &Rect, Flags);
  58.         OffsetRect(&Rect, -1, -1);
  59.         Canvas->Font->Color = clBtnShadow;
  60.         DrawText(Canvas->Handle, Text.c_str(), Text.Length(), &Rect, Flags);
  61.     }
  62.     else
  63.         DrawText(Canvas->Handle, Text.c_str(), Text.Length(), &Rect, Flags);
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TFLabel::SetBorder(int Value)
  67. {
  68.     if(FBorder!=Value)
  69.     {
  70.         FBorder=Value;
  71.         Paint();
  72.         Width++;
  73.         Width--;
  74.     }
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TFLabel::Paint()
  78. {
  79.     TLabel::Paint();
  80.     Canvas->Pen->Style=FBorder?psSolid:psClear;
  81.     Canvas->Pen->Color=FBorder?clRed:clBlack;
  82.     if(FBorder==0 || FBorder==1)
  83.         Canvas->Rectangle(0,0,Width,Height);
  84.     else if(FBorder==2)
  85.         Canvas->RoundRect(0,0,Width,Height,20,20);
  86. }