⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxcontainer.pas

📁 delphi控件可以很好实现应用程序的界面设计
💻 PAS
📖 第 1 页 / 共 2 页
字号:

{*******************************************************************}
{                                                                   }
{   Design eXperince Visual Component Library                       }
{   Container Component (dxContainer)                               }
{                                                                   }
{   Copyright (c) 2002 APRIORI business solutions AG                }
{   (W)ritten by M. Hoffmann - ALL RIGHTS RESERVED.                 }
{                                                                   }
{   DEVELOPER NOTES:                                                }
{   ==========================================================      }
{   This file is part of a component suite called Design            }
{   eXperience and may be used in freeware- or commercial           }
{   applications. The package itself is distributed as              }
{   freeware with full sourcecodes.                                 }
{                                                                   }
{   Feel free to fix bugs or include new features if you are        }
{   familiar with component programming. If so, please email        }
{   me your modifications, so it will be possible for me to         }
{   include nice improvements in further releases:                  }
{                                                                   }
{*******************************************************************}

unit dxContainer;

{$I dxVer.inc}

interface

uses
{$IFDEF DELPHI6}
  TypInfo,
{$ENDIF}
  Windows, Classes, Controls, Graphics, StdCtrls, dxCore, dxCoreUtils;

type
{ TdxPaintEvent }

  TdxPaintEvent = procedure(Sender: TObject; Rect: TRect; ACanvas: TCanvas;
    AFont: TFont) of object;

{ TdxEnabledMode }

{$IFDEF DELPHI6}
  TdxEnabledMode = (emAffectChilds, emNormal);
{$ENDIF}

{ TdxCustomContainer }

  TdxCustomContainer = class(TdxCustomControl)
  private
    FAlignment: TAlignment;
    FBorderWidth: TBorderWidth;
    FBoundColor: TColor;
    FBoundLines: TdxBoundLines;
  {$IFDEF DELPHI6}
    FEnabledMode: TdxEnabledMode;
  {$ENDIF}
    FFocusable: Boolean;
    FGlyph: TBitmap;
    FGlyphLayout: TdxGlyphLayout;
    FLayout: TTextLayout;
    FShowBoundLines: Boolean;
    FShowCaption: Boolean;
    FSpacing: Byte;
    FWordWrap: Boolean;
  {$IFDEF DELPHI6}
    FOnEnabledChanged: TNotifyEvent;
  {$ENDIF}
    FOnPaint: TdxPaintEvent;
    procedure SetAlignment(Value: TAlignment);
    procedure SetBorderWidth(Value: TBorderWidth);
    procedure SetBoundColor(Value: TColor);
    procedure SetBoundLines(Value: TdxBoundLines);
  {$IFDEF DELPHI6}
    procedure SetEnabledMode(Value: TdxEnabledMode);
  {$ENDIF}
    procedure SetGlyph(Value: TBitmap);
    procedure SetGlyphLayout(Value: TdxGlyphLayout);
    procedure SetLayout(Value: TTextLayout);
    procedure SetShowBoundLines(Value: Boolean);
    procedure SetShowCaption(Value: Boolean);
    procedure SetSpacing(Value: Byte);
    procedure SetWordWrap(Value: Boolean);
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    procedure AdjustClientRect(var Rect: TRect); override;
  {$IFDEF DELPHI6}
    procedure HookEnabledChanged; override;
  {$ENDIF}
    procedure HookMouseDown; override;
    procedure HookPosChanged; override;
    property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
    property BorderWidth: TBorderWidth read FBorderWidth write SetBorderWidth default 0;
    property BoundColor: TColor read FBoundColor write SetBoundColor default clGray;
    property BoundLines: TdxBoundLines read FBoundLines write SetBoundLines default [];
  {$IFDEF DELPHI6}
    property EnabledMode: TdxEnabledMode read FEnabledMode write SetEnabledMode
      default emNormal;
  {$ENDIF}
    property Focusable: Boolean read FFocusable write FFocusable default False;
    property Glyph: TBitmap read FGlyph write SetGlyph;
    property GlyphLayout: TdxGlyphLayout read FGlyphLayout write SetGlyphLayout
      default glCenter;
    property Layout: TTextLayout read FLayout write SetLayout default tlCenter;
    property Height default 41;
    property ShowBoundLines: Boolean read FShowBoundLines write SetShowBoundLines
      default True;
    property ShowCaption: Boolean read FShowCaption write SetShowCaption
      default False;
    property Spacing: Byte read FSpacing write SetSpacing default 5;
    property Width default 185;
    property WordWrap: Boolean read FWordWrap write SetWordWrap default False;
  {$IFDEF DELPHI6}
    property OnEnabledChanged: TNotifyEvent read FOnEnabledChanged write FOnEnabledChanged;
  {$ENDIF}
    property OnPaint: TdxPaintEvent read FOnPaint write FOnPaint;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Paint; override;
  end;

{ TdxContainer }

  TdxContainer = class(TdxCustomContainer)
  published
    property Alignment;
    property AutoSize;
    property BorderWidth;
    property BoundColor;
    property BoundLines;
    property Caption;
    property Color;
    property Enabled;
  {$IFDEF DELPHI6}
    property EnabledMode;
  {$ENDIF}
    property Focusable;
    property Glyph;
    property GlyphLayout;
    property Layout;
    property ParentColor;
    property ShowBoundLines;
    property ShowCaption;
    property Spacing;
    property WordWrap;
  {$IFDEF DELPHI6}
    property OnEnabledChanged;
  {$ENDIF}
    property OnDblClick;
    property OnPaint;
    property OnResize;
  end;

implementation

{ TdxCustomContainer }

{-----------------------------------------------------------------------------
  Procedure: TdxCustomContainer.Create
  Author:    mh
  Date:      20-Aug-2002
  Arguments: AOwner: TComponent
  Result:    None
-----------------------------------------------------------------------------}

constructor TdxCustomContainer.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle + [csAcceptsControls];
  Height := 41;
  Width := 185;
  FAlignment := taCenter;
  FBoundColor := clGray;
  FBoundLines := [];
{$IFDEF DELPHI6}
  FEnabledMode := emNormal;
{$ENDIF}
  FFocusable := False;
  FGlyph := TBitmap.Create;
  FGlyph.Assign(nil);
  FGlyphLayout := glCenter;
  FLayout := tlCenter;
  FShowBoundLines := True;
  FShowCaption := False;
  FSpacing := 5;
  FWordWrap := False;
end;

{-----------------------------------------------------------------------------
  Procedure: TdxCustomContainer.Destroy
  Author:    mh
  Date:      20-Aug-2002
  Arguments: None
  Result:    None
-----------------------------------------------------------------------------}

destructor TdxCustomContainer.Destroy;
begin
  FGlyph.Free;
  inherited;
end;

{-----------------------------------------------------------------------------
  Procedure: TdxCustomContainer.CreateParams
  Author:    mh
  Date:      20-Aug-2002
  Arguments: var Params: TCreateParams
  Result:    None
-----------------------------------------------------------------------------}

procedure TdxCustomContainer.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
    WindowClass.Style := WindowClass.Style and not (CS_HREDRAW or CS_VREDRAW);
end;

{-----------------------------------------------------------------------------
  Procedure: TdxCustomContainer.HookEnabledChanged
  Author:    mh
  Date:      20-Aug-2002
  Arguments: None
  Result:    None
-----------------------------------------------------------------------------}

{$IFDEF DELPHI6}
procedure TdxCustomContainer.HookEnabledChanged;
var
  i: Integer;
begin
  inherited;
  if FEnabledMode = emAffectChilds then
  for i := 0 to ControlCount - 1 do
    if IsPublishedProp(Controls[i], 'Enabled') then
      SetPropValue(Controls[i], 'Enabled', Enabled);
  if Assigned(FOnEnabledChanged) then
    FOnEnabledChanged(Self);
end;
{$ENDIF}

{-----------------------------------------------------------------------------
  Procedure: TdxCustomContainer.HookMouseDown
  Author:    mh
  Date:      20-Aug-2002
  Arguments: None
  Result:    None
-----------------------------------------------------------------------------}

procedure TdxCustomContainer.HookMouseDown;
begin
  case FFocusable of
    True:
      inherited;
    False:
      begin
        DrawState := DrawState + [dsClicked];
        InternalRedraw;
      end;
  end;
end;

{-----------------------------------------------------------------------------
  Procedure: TdxCustomContainer.HookPosChanged
  Author:    mh
  Date:      20-Aug-2002
  Arguments: None
  Result:    None
-----------------------------------------------------------------------------}

procedure TdxCustomContainer.HookPosChanged;
begin
  inherited;
  InternalRedraw;
end;

{-----------------------------------------------------------------------------
  Procedure: TdxCustomContainer.AdjustClientRect
  Author:    mh
  Date:      20-Aug-2002
  Arguments: var Rect: TRect
  Result:    None
-----------------------------------------------------------------------------}

procedure TdxCustomContainer.AdjustClientRect(var Rect: TRect);
begin
  inherited AdjustClientRect(Rect);
  dxAdjustBoundRect(BorderWidth, FShowBoundLines, FBoundLines, Rect);
  if not FGlyph.Empty then
    Inc(Rect.Left, FGlyph.Width);
end;

{-----------------------------------------------------------------------------
  Procedure: TdxCustomContainer.SetAlignment
  Author:    mh
  Date:      20-Aug-2002

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -