FLabel.~cpp
资源名称:FLabel.rar [点击查看]
上传用户:hnxhmj
上传日期:2020-10-13
资源大小:14k
文件大小:3k
源码类别:
Static控件
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "FLabel.h"
- #pragma package(smart_init)
- //---------------------------------------------------------------------------
- // ValidCtrCheck is used to assure that the components created do not have
- // any pure virtual functions.
- //
- static inline void ValidCtrCheck(TFLabel *)
- {
- new TFLabel(NULL);
- }
- //---------------------------------------------------------------------------
- __fastcall TFLabel::TFLabel(TComponent* Owner)
- : TLabel(Owner)
- {
- }
- //---------------------------------------------------------------------------
- namespace Flabel
- {
- void __fastcall PACKAGE Register()
- {
- TComponentClass classes[1] = {__classid(TFLabel)};
- RegisterComponents("Custom", classes, 0);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFLabel::SetTextSpace(int Value)
- {
- if(FTextSpace!=Value)
- {
- //int Diff=Value-FTextSpace;
- FTextSpace=Value;
- //int len=(WideString(Caption)).Length()-1;
- //if(len) Width+=len*Diff;//加上TextSpace
- Width++;
- Width--;
- //AdjustBounds();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFLabel::DoDrawText(Windows::TRect &Rect, int Flags)
- {
- AnsiString Text;
- Text = GetLabelText();
- if( (Flags && DT_CALCRECT!=0) && ((Text == "") || ( ShowAccelChar && Text.c_str()[0] == '&' && Text.c_str()[1] == ' ')))
- Text = Text + " ";
- if(!ShowAccelChar) Flags = Flags | DT_NOPREFIX;
- Flags = DrawTextBiDiModeFlags(Flags);
- Canvas->Font = Font;
- SetTextCharacterExtra(Canvas->Handle,TextSpace); //设置字符间距;
- if(!Enabled)
- {
- OffsetRect(&Rect, 1, 1);
- Canvas->Font->Color = clBtnHighlight;
- DrawText(Canvas->Handle, Text.c_str(), Text.Length(), &Rect, Flags);
- OffsetRect(&Rect, -1, -1);
- Canvas->Font->Color = clBtnShadow;
- DrawText(Canvas->Handle, Text.c_str(), Text.Length(), &Rect, Flags);
- }
- else
- DrawText(Canvas->Handle, Text.c_str(), Text.Length(), &Rect, Flags);
- }
- //---------------------------------------------------------------------------
- void __fastcall TFLabel::SetBorder(int Value)
- {
- if(FBorder!=Value)
- {
- FBorder=Value;
- Paint();
- Width++;
- Width--;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFLabel::Paint()
- {
- TLabel::Paint();
- Canvas->Pen->Style=FBorder?psSolid:psClear;
- Canvas->Pen->Color=FBorder?clRed:clBlack;
- if(FBorder==0 || FBorder==1)
- Canvas->Rectangle(0,0,Width,Height);
- else if(FBorder==2)
- Canvas->RoundRect(0,0,Width,Height,20,20);
- }