亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > Delphi > 正文

Delphi控件制作技巧[一]

2019-11-18 18:03:10
字體:
來源:轉載
供稿:網友
 

unit USWLMSelectDa;

{$S-,W-,R-}                                            
{$C PRELOAD}

interface

uses
  Windows,Messages,SysUtils, Types, Classes, Graphics, Controls,StdCtrls,Forms,
  StrUtils,Math,ADODB,TFlatButtonUnit,USWLMStyleEdit;

type
  TEditDataType = (sdString, sdInteger,sdFloat,sdMoney);
  TVAlignment = (tvaTopJustify, tvaCenter, tvaBottomJustify);
  TDataStyle = (dsBm, dsZj, dsMc);
type
  TSelectDa = class(TCustomControl)
  private
    FPen: TPen;
    FBrush:TBrush;
    FFont:TFont;
    FCaption:string;
    FBmText:string;
    FZjText:string;
    FMcText:string;
    FDataType: TEditDataType;
    FPrecision: Integer;
    FReadOnly:Boolean;
    FEditFont:TFont;
    FHAlignment : TAlignment;
    FVAlignment : TVAlignment;
    FEdit:TStyleEdit;
    FButton:TFlatButton;
    FTitleName:string;
    FTableName:string;
    FDataStyle:TDataStyle;
    FBmField:string;
    FZjField:string;
    FMcField:string;
    FOnClick: TNotifyEvent;
    FOnEnter: TNotifyEvent;
    FOnExit: TNotifyEvent;
    FOnKeyPress: TKeyPressEvent;
    procedure SetPen(const Value:TPen);
    procedure SetBrush(const Value:TBrush);
    procedure SetFont(const Value:TFont);
    procedure SetCaption(const Value:string);
    procedure SetBmText(const Value:string);
    procedure SetZjText(const Value:string);
    procedure SetMcText(const Value:string);
    procedure SetDataType(const Value: TEditDataType);
    procedure SetPrecision(const Value: Integer);
    procedure SetReadOnly(const Value:Boolean);
    procedure SetEditFont(const Value:TFont);
    procedure SetHAlignment(const Value:TAlignment);
    procedure SetVAlignment(const Value:TVAlignment);
    procedure SetTitleName(const Value:string);
    procedure SetTableName(const Value:string);
    procedure SetDataStyle(const Value:TDataStyle);
    procedure SetBmField(const Value:string);
    procedure SetZjField(const Value:string);
    procedure SetMcField(const Value:string);
    function  GetAsFloat(): string;
    function  GetAsMoney(): string;
    function  GetAsInteger(): string;
    function  GetAsText(): string;
    procedure SetAsFloat(const Value: string);
    procedure SetAsMoney(const Value: string);
    procedure SetAsInteger(const Value: string);
    procedure SetAsText(const Value: string);
    procedure StyleChanged(Sender: TObject);
    procedure SetBackColor(const Value : TColor);
    procedure SetColorOnEnter(const Value : TColor);
    procedure DoClick(Sender: TObject);
    procedure DoEnter(Sender: TObject);
    procedure DoExit(Sender: TObject);
    procedure DoKeyPress(Sender: TObject; var Key: Char);
  protected
    procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
  published
    property Pen: TPen read FPen write SetPen;
    property Brush: TBrush read FBrush write SetBrush;
    property Font: TFont read FFont write SetFont;
    property Caption:string read FCaption write SetCaption;
    property Bm:string read FBmText write SetBmText ;
    property Zjf:string read FZjText write SetZjText ;
    property Mc:string read FMcText write SetMcText ;
    property Text:string read FMcText write SetMcText;
    property DataType: TEditDataType read FDataType write SetDataType default SdString;
    property Precision: Integer read Fprecision write SetPrecision default 2;
    property ReadOnly: Boolean read FReadOnly write SetReadOnly default False;
    property EditFont: TFont read FEditFont write SetEditFont;
    property HAlignment:TAlignment read FHAlignment write SetHAlignment default taLeftJustify;
    property VAlignment:TVAlignment read FVAlignment write SetVAlignment default tvaBottomJustify;
    property TitleName:string read FTitleName write SetTitleName ;
    property TableName:string read FTableName write SetTableName ;
    property DataStyle:TDataStyle read FDataStyle write SetDataStyle default dsBm;
    property BmField:string read FBmField write SetBmField ;
    property ZjField:string read FZjField write SetZjField ;
    property McField:string read FMcField write SetMcField ;
    property AsFloat:string read GetAsFloat {write SetAsFloat};
    property AsMoney:string read GetAsMoney {write SetAsMoney};
    property AsInt: string read GetAsInteger {write SetAsInteger};
    property AsStr: string read GetAsText write SetAsText;
    property OnClick: TNotifyEvent read FOnClick write FOnClick;
    property OnKeyPress: TKeyPressEvent read FOnKeyPress write FOnKeyPress;
    property OnEnter: TNotifyEvent read FOnEnter write FOnEnter;
    property OnExit: TNotifyEvent read FOnExit write FOnExit;
    property BackColor : TColor write SetBackColor;
    property ColorOnEnter : TColor write SetColorOnEnter;
    property AlignDisabled;
    property VisibleDockClientCount;
    property ControlCount;
    property ParentWindow;
    property Showing;
    property TabOrder;
    property TabStop;
  end;

procedure Register;

implementation

uses Consts;

procedure TSelectDa.SetPen(const Value: TPen);
begin
  FPen.Assign(Value);
  Invalidate;
end;

procedure TSelectDa.SetBrush(const Value:TBrush);
begin
  FBrush.Assign(Value);
  Invalidate;
end;

procedure TSelectDa.SetFont(const Value:TFont);
begin
  FFont.Assign(Value);
  Invalidate;
end;

procedure TSelectDa.SetCaption(const Value:string);
begin
  if FCaption <> Value then
  begin
    FCaption:=Value;
    Invalidate;
  end;
end;

procedure TSelectDa.SetBmText(const Value:string);
begin
  if FBmText <> Value then
  begin
    FBmText:=Value;
    Invalidate;
  end;
end;

procedure TSelectDa.SetZjText(const Value:string);
begin
  if FZjText <> Value then
  begin
    FZjText:=Value;
  end;
end;

procedure TSelectDa.SetMcText(const Value:string);
begin
  if FMcText <> Value then
  begin
    FMcText:=Value;
    Invalidate;
  end;
end;

procedure TSelectDa.SetReadOnly(const Value:Boolean);
begin
  if FReadOnly<>Value then
  begin
    FReadOnly:=Value;
    Invalidate;
  end;
end;

procedure TSelectDa.SetEditFont(const Value:TFont);
begin
  FEditFont.Assign(Value);
  Invalidate;
end;

procedure TSelectDa.SetPrecision(const Value: Integer);
begin
  if Fprecision<>Value then
  begin
    case Value of
    1..6:FPrecision:=Value;
    else FPrecision:=2;
    end;
    Invalidate;
  end;
end;

procedure TSelectDa.SetDataType(const Value: TEditDataType);
begin
  if FDataType <> Value then
  begin
    FDataType:=Value;
    case FDataType of
      SdString:FEdit.InputStyle:=IsString;
      SdInteger:FEdit.InputStyle:=IsInteger;
      SdFloat:FEdit.InputStyle:=IsFloat;
      SdMoney:FEdit.InputStyle:=IsMoney;
      else FEdit.InputStyle:=IsString;
    end;
    Invalidate;
  end;
end;

procedure TSelectDa.SetHAlignment(const Value:TAlignment);
begin
  if FHAlignment <> Value then
  begin
      FHAlignment:=Value;
      Invalidate;
  end;
end;

procedure TSelectDa.SetVAlignment(const Value:TVAlignment);
begin
  if FVAlignment <> Value then
  begin
      FVAlignment:=Value;
      Invalidate;
  end;
end;

procedure TSelectDa.SetTitleName(const Value:string);
begin
  if FTitleName<>Value then FTitleName:=Value;
end;

procedure TSelectDa.SetTableName(const Value:string);
begin
  if FTableName<>Value then
  begin
    FTableName:=Value;
    Invalidate;
  end;
end;

procedure TSelectDa.SetDataStyle(const Value:TDataStyle);
begin
  if FDataStyle<>Value then FDataStyle:=Value;
end;

procedure TSelectDa.SetBmField(const Value:string);
begin
  if FBmField<>Value then
  begin
      FBmField:=Value;
      Invalidate;
  end;
end;

procedure TSelectDa.SetZjField(const Value:string);
begin
  if FZjField<>Value then  FZjField:=Value;
end;

procedure TSelectDa.SetMcField(const Value:string);
begin
  if FMcField<>Value then
  begin
      FMcField:=Value;
      Invalidate;
  end;
end;

function  TSelectDa.GetAsFloat: string;
  function StrToDouble(S:string):Double;
  begin
    if not trystrToFloat(s,Result) then Result:=0;
  end;
begin
  case FPrecision of
  1..6:  Result:=FormatFloat('###0.'+DupeString('0',FPrecision),StrToDouble(FMcText));
  else  Result:=FormatFloat('###0.00',StrToDouble(FMcText));
  end;
end;

function  TSelectDa.GetAsMoney: string;
  function StrToDouble(S:string):Double;
  begin
    if not trystrToFloat(s,Result) then Result:=0;
  end;
begin
  Result:=FormatFloat('###0.00',StrToDouble(FMcText));
end;

function  TSelectDa.GetAsInteger: string;
  Function StrToInteger(S:string):integer;
  begin
    if not trystrToInt(s,Result) then Result:=0;
  end;
begin
  Result:=IntToStr(StrToInteger(FMcText));
end;

function  TSelectDa.GetAsText: string;
begin
  Result:=FMcText;
end;

procedure TSelectDa.SetAsFloat(const Value: string);
  function StrToDouble(S:string):Double;
  begin
    if not trystrToFloat(s,Result) then Result:=0;
  end;
var
  f:Double;
begin
  f:=StrToDouble(Value);
  case FPrecision of
  1..6:
  begin
    f:=RoundTo(f,-FPrecision);
    SetMcText(FormatFloat('###0.'+DupeString('0',FPrecision),f));
  end
  else
  begin
    f:=RoundTo(f,-2);
    SetMcText(FormatFloat('###0.00',f));
  end;
  end;
end;

procedure TSelectDa.SetAsMoney(const Value: string);
  function StrToDouble(S:string):Double;
  begin
    if not trystrToFloat(s,Result) then Result:=0;
  end;
var
  f:Double;
begin
  f:=StrToDouble(Value);
  f:=RoundTo(f,-2);
  SetMcText(FormatFloat('###0.00',f));
end;

procedure TSelectDa.SetAsInteger(const Value: string);
  Function StrToInteger(S:string):integer;
  begin
    if not trystrToInt(s,Result) then Result:=0;
  end;
var
  i:Integer;
begin
  i:=StrToInteger(Value);
  SetMcText(IntToStr(i));
end;

procedure TSelectDa.SetAsText(const Value: string);
begin
  SetMcText(Value);
end;

procedure TSelectDa.StyleChanged(Sender: TObject);
begin
  Invalidate;
end;

procedure TSelectDa.SetBackColor(const Value : TColor);
begin
  FEdit.BackColor:=Value;
end;

procedure TSelectDa.SetColorOnEnter(const Value : TColor);
begin
  FEdit.ColorOnEnter:=Value;
end;

constructor TSelectDa.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Width:=188;
  Height:=20;
  FCaption:='未命名';
  FBmText:='';
  FZjText:='';
  FMcText:='';
  FReadOnly:=False;
  FHAlignment:=taLeftJustify;
  FVAlignment:=tvaBottomJustify;
  FDataType:=SdString;
  FPrecision:=2;
  FTitleName:='';
  FTableName:='';
  FDataStyle:=dsBm;
  FBmField:='';
  FZjField:='';
  FMcField:='';
  FPen := TPen.Create;
  FPen.OnChange:=StyleChanged;
  FBrush := TBrush.Create;
  FBrush.OnChange:=StyleChanged;
  FFont := TFont.Create;
  FFont.OnChange:=StyleChanged;
  FFont.Charset:=GB2312_CHARSET;
  FFont.Name:='宋體';
  FFont.Size:=9;
  FEditFont := TFont.Create;
  FEditFont.OnChange:=StyleChanged;
  FEditFont.Charset:=GB2312_CHARSET;
  FEditFont.Name:='宋體';
  FEditFont.Size:=9;
  FEdit:=TStyleEdit.Create(Self);
  FEdit.Parent:=Self;
  FEdit.BorderStyle:=bsNone;
  FEdit.InputStyle:=isString;
  FEdit.OnKeyPress:=DoKeyPress;
  FEdit.OnEnter:=DoEnter;
  FEdit.OnExit:=DoExit;
  FButton:=TFlatButton.Create(Self);
  FButton.Parent:=Self;
  FButton.Font:=FFont;
  FButton.ColorBorder:=FBrush.Color;
  FButton.Color:=FBrush.Color;
  FButton.ColorDown:=FBrush.Color;
  FButton.ColorShadow:=FBrush.Color;
  FButton.ColorFocused:=FBrush.Color;
  FButton.Width:=19;
  FButton.Caption:='…';
  FButton.OnClick:=DoClick;
end;

procedure TSelectDa.Paint;
var
  aText:Pchar;
  aRect:TRect;
  Flag:DWord;
begin
  with Canvas do
  begin
    Font:=FFont;
    Pen:=FPen;
    Brush:=FBrush;
    FillRect(ClientRect);
    if FBmText<>'' then aText:=Pchar(FCaption+'['+FBmText+']') else aText:=Pchar(FCaption);
    aRect:=Rect(ClientRect.Left+FPen.Width, ClientRect.Top+FPen.Width, ClientRect.Right-FPen.Width, ClientRect.Bottom-FPen.Width);
    DrawText(Handle, aText, StrLen(aText), aRect, (DT_SINGLELINE or DT_VCENTER) or DT_LEFT);
    Inc(aRect.Left,TextWidth(aText));
    Dec(aRect.Right,FButton.Width);
    MoveTo(aRect.Left,aRect.Bottom);
    LineTo(aRect.Right,aRect.Bottom);
    Inc(aRect.Left,FPen.Width);
    if FReadOnly then
    begin
      FEdit.Visible:=False;
      FButton.Visible:=False;
      Flag:=DT_SINGLELINE;
      case FHAlignment of
        taLeftJustify:Flag:=Flag or DT_LEFT;
        taRightJustify:Flag:=Flag or DT_RIGHT;
        taCenter:Flag:=Flag or DT_CENTER;
        else Flag:=Flag or DT_LEFT;
      end;
      case FVAlignment of
        tvaTopJustify:Flag:=Flag or DT_TOP;
        tvaCenter:Flag:=Flag or DT_VCENTER;
        tvaBottomJustify:Flag:=Flag or DT_BOTTOM;
        else Flag:=Flag or DT_BOTTOM;
      end;
      Font:=FEditFont;
      case FDataType of
        SdString:DrawText(Handle, PChar(AsStr),  StrLen(PChar(AsStr)), aRect, Flag);
        SdInteger:DrawText(Handle, PChar(AsInt), StrLen(PChar(AsInt)), aRect, Flag);
        SdFloat:DrawText(Handle, PChar(AsFloat), StrLen(PChar(AsFloat)), aRect, Flag);
        SdMoney:DrawText(Handle, PChar(AsMoney), StrLen(PChar(AsMoney)), aRect, Flag);
      end;
    end
    else
    begin
      FEdit.Alignment:=FHAlignment;
      FEdit.Font:=FEditFont;
      FEdit.Text:=FMcText;
      FEdit.Width:=aRect.Right-aRect.Left;
      FEdit.Height:=Min(Max(TextHeight(FMcText),TextHeight(FCaption)),aRect.Bottom-aRect.Top);
      FEdit.Left:=aRect.Left;
      case FVAlignment of
        tvaTopJustify:FEdit.Top:=aRect.Top;
        tvaCenter:FEdit.Top:=aRect.Top+(aRect.Bottom-aRect.Top-FEdit.Height)div 2;
        tvaBottomJustify:FEdit.Top:=aRect.Top+(aRect.Bottom-aRect.Top-FEdit.Height);
        else FEdit.Top:=aRect.Top;
      end;
      FButton.Left:=aRect.Right;
      FButton.Top:=aRect.Top;
      FButton.Height:=aRect.Bottom-aRect.Top;
      if (FDataType=SdString) and (FBmField<>'') and (FMcField<>'') and (FTableName<>'') then FButton.Visible:=True
      else FButton.Visible:=False;
    end;
  end;
end;

destructor TSelectDa.Destroy;
begin
  FPen.Free;
  FBrush.Free;
  FFont.Free;
  FEditFont.Free;
  if Assigned(FEdit) then FreeAndNil(FEdit);
  if Assigned(FButton) then FreeAndNil(FButton);
  inherited Destroy;
end;

procedure TSelectDa.DoClick(Sender: TObject);
begin
  if Assigned(FOnClick) then FOnClick(Self);
end;

procedure TSelectDa.DoEnter(Sender: TObject);
begin
  if Assigned(FOnEnter) then FOnEnter(Self);
end;

procedure TSelectDa.DoExit(Sender: TObject);
begin
  if Assigned(FOnExit) then FOnExit(Self);
end;

procedure TSelectDa.DoKeyPress(Sender: TObject; var Key: Char);
begin
  if Assigned(FOnKeyPress) then FOnKeyPress(Self,Key);
end;

procedure Register;
begin
  RegisterComponents('swlmsoft', [TSelectDa]);
end;

end.


上一篇:Delphi關于線程的消息處理

下一篇:Delphi+MapX5中使用自定義字體符號

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
久久6精品影院| 亚洲欧洲日韩国产| 精品无人区太爽高潮在线播放| 亚洲人成在线一二| 亚洲精品suv精品一区二区| 欧美成人午夜影院| 久久青草福利网站| 日韩天堂在线视频| 成人亚洲欧美一区二区三区| 亚洲欧洲日韩国产| 一区二区成人av| 亚洲最大的免费| 亚洲国产精品一区二区三区| 日韩中文字幕视频在线| 亚洲视频在线免费看| 免费不卡欧美自拍视频| 国产精品99导航| 国产视频精品xxxx| 国产精品成人v| 欧美香蕉大胸在线视频观看| 国产欧美日韩综合精品| 88国产精品欧美一区二区三区| 欧美大片在线看免费观看| 成人午夜激情免费视频| 日韩在线视频导航| 欧美限制级电影在线观看| 中文字幕国产日韩| 欧美多人乱p欧美4p久久| 亚洲精品久久久久久久久| 欧美限制级电影在线观看| 国产亚洲精品久久久久久| 亚洲国产天堂久久综合网| 麻豆国产精品va在线观看不卡| 欧美性猛交xxxxx水多| 69精品小视频| 久久亚洲影音av资源网| 欧美黑人一区二区三区| 欧美亚洲激情在线| 欧美性高跟鞋xxxxhd| 日韩av最新在线观看| 日韩美女av在线| 中文字幕亚洲综合久久筱田步美| 久久亚洲精品中文字幕冲田杏梨| 91久久在线视频| 欧美性xxxxx极品娇小| 亚洲女人天堂av| 91精品视频免费观看| 91网站在线免费观看| 亚洲一区二区在线播放| 久久久国产视频| 国产一区二区三区在线看| 成人网在线免费看| 国产精品视频久久久| 日韩精品一区二区视频| 日韩av一区二区在线观看| 日韩小视频在线观看| 国产欧美精品一区二区三区-老狼| 91影院在线免费观看视频| 国产91精品久久久久久久| 亚洲bt天天射| 国产视频精品va久久久久久| 国产精品视频精品| 九九精品视频在线观看| 91社区国产高清| 国产精品视频中文字幕91| 亚洲国产欧美一区二区三区同亚洲| 深夜精品寂寞黄网站在线观看| 亚洲已满18点击进入在线看片| 亚洲欧美制服中文字幕| 中文国产亚洲喷潮| 欧洲精品毛片网站| 日韩中文字幕网| 亚洲成人av在线| 日韩欧美中文字幕在线观看| 伊人久久男人天堂| 狠狠做深爱婷婷久久综合一区| 欧美国产亚洲精品久久久8v| 国产一区二区三区在线观看视频| 久久男人资源视频| 精品视频www| 538国产精品视频一区二区| 国产亚洲激情在线| 国产成人激情视频| 国a精品视频大全| 国产精品老女人视频| 亚洲精品成a人在线观看| 日韩美女中文字幕| 俺去了亚洲欧美日韩| 日本欧美爱爱爱| 亚洲性猛交xxxxwww| 国产午夜精品免费一区二区三区| 精品国内自产拍在线观看| 欧美精品www| 日本久久久久久久久久久| 久久99热这里只有精品国产| 中文字幕视频一区二区在线有码| 菠萝蜜影院一区二区免费| 亚洲级视频在线观看免费1级| 一区二区三区无码高清视频| 亚洲电影免费观看高清| 亚洲女人被黑人巨大进入| 欧美国产日韩一区二区| 久久欧美在线电影| 欧美大片大片在线播放| 欧美日韩国产综合视频在线观看中文| 美女撒尿一区二区三区| 亚洲第一区中文99精品| 久久99精品久久久久久噜噜| 国产日韩欧美中文在线播放| 91精品免费久久久久久久久| 欧美成人一区在线| 国产福利精品av综合导导航| 中文字幕精品av| 日韩精品极品毛片系列视频| 中文字幕不卡在线视频极品| 国产91精品高潮白浆喷水| 狠狠久久五月精品中文字幕| 2024亚洲男人天堂| 久久成人这里只有精品| 97精品伊人久久久大香线蕉| 亚洲成人黄色网| www.欧美三级电影.com| 欧美老女人www| 国产精品第二页| 国产成人精品视频在线| 日韩在线免费观看视频| 精品久久久久久久久久久久久| 国产精品福利无圣光在线一区| 欧美另类极品videosbest最新版本| 国产视频亚洲精品| 国产免费成人av| 米奇精品一区二区三区在线观看| 成人激情综合网| 日韩成人av在线播放| 成人天堂噜噜噜| 国产精品狠色婷| 亚洲第一免费播放区| 亚洲成人久久久久| 国产精品成人观看视频国产奇米| 狠狠色噜噜狠狠狠狠97| 国产精品视频内| 国产精品69久久| 日韩国产欧美区| 在线观看亚洲视频| 国产精品亚发布| 国产精品久久久久免费a∨大胸| 国产中文字幕91| 日本伊人精品一区二区三区介绍| 欧美成人午夜激情在线| 日韩中文字幕网址| 97国产精品视频人人做人人爱| 26uuu另类亚洲欧美日本老年| 91成人福利在线| 亚洲视频欧洲视频| 久久精品久久久久久国产 免费| 欧美大成色www永久网站婷| 伊人久久五月天| 成人午夜两性视频| 人人澡人人澡人人看欧美| 永久免费精品影视网站| 国产精品丝袜视频| 成人激情视频小说免费下载| 亚洲天堂男人天堂女人天堂| 欧美黑人国产人伦爽爽爽|