1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
unit DragComponentContainer;
interface
uses
SysUtils, Classes, Graphics, Controls, Dialogs,ComponentContainer;
type
TDragComponentContainer = class(TCustomControl)
private
m_minWidth: integer;
m_minHeight: integer;
procedure CanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean);
protected
procedure Paint; override;
public
RowsCont: TComponentContainer;
ColsCont: TComponentContainer;
DataCont: TComponentContainer;
BtnsCont: TComponentContainer;
constructor Create(AOwner:TComponent); override;
published
property minwidth:integer read m_minWidth write m_minWidth;
property minheight:integer read m_minHeight write m_minHeight;
property Align;
property Caption;
property Color;
property Cursor;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property Hint;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property Visible;
property Anchors;
property OnCanResize;
end;
procedure Register;
implementation
constructor TDragComponentContainer.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
RowsCont:=TComponentContainer.create(self);
ColsCont:=TComponentContainer.create(self);
DataCont:=TComponentContainer.create(self);
BtnsCont:=TComponentContainer.create(self);
onCanResize:=CanResize;
RowsCont.Parent:=self;
ColsCont.Parent:=self;
DataCont.Parent:=self;
BtnsCont.Parent:=self;
Width:=250;
Height:=150;
minwidth:=width;
minheight:=Height;
ColsCont.Width:=Width-40 - 50;
ColsCont.Height:=15;
ColsCont.Left:=40-1;
ColsCont.top:=0;
ColsCont.visible:=true;
ColsCont.color:=clBlue;
ColsCont.anchors:=[akLeft, akTop, akRight];
RowsCont.Width:=40;
RowsCont.Left:=0;
RowsCont.height:=height-ColsCont.height +1;
RowsCont.top:=ColsCont.height-1;
RowsCont.visible:=true;
RowsCont.color:=clGreen;
RowsCont.anchors:=[akLeft, akTop, akBottom];
DataCont.Width:= ColsCont.Width;
DataCont.Left:=ColsCont.Left;
DataCont.height:=height-ColsCont.height +1;
DataCont.top:=RowsCont.top;
DataCont.visible:=true;
DataCont.color:=clFuchsia;
DataCont.anchors:=[akLeft, akTop, akRight, akBottom];
BtnsCont.Color:=clSilver;
BtnsCont.top:=0;
BtnsCont.Height:=height;
BtnsCont.left:=ColsCont.left+ ColsCont.Width+5;
BtnsCont.Width:=width-BtnsCont.left;
BtnsCont.visible:=true;
BtnsCont.anchors:=[akTop, akRight, akBottom];
end;
procedure Register;
begin
RegisterComponents('Samples', [TDragComponentContainer]);
end;
procedure TDragComponentContainer.CanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean);
begin
if((NewWidth<minWidth)) then NewWidth:=minWidth;
if((NewHeight<minHeight)) then NewHeight:=minHeight;
resize:=true;
end;
procedure TDragComponentContainer.Paint;
begin
inherited Paint;
with Canvas do
begin
Brush.Style:=bsSolid;
Brush.Color:=clBtnFace;
Pen.Color:=clRed;
Rectangle(0,0,Width,Height);
//Rectangle(rowsBlockWidth+colsBlockWidth+5,0,btnsBlockWidth,height);
end;
RowsCont.Repaint;
ColsCont.Repaint;
DataCont.Repaint;
BtnsCont.Repaint;
end; |
Partager