我参照TPictureOpenDialog写了一个类似的OpenDialog,结果却不如愿,
在procedure DoShow中,GetClientRect时返回的Rect总是 top=0,bottom=0,left=0
为什么,望高人指点,谢谢。
代码如下:
unit RepOpenDialog;
interface
Uses
Dialogs,graphics,extctrls,stdctrls,buttons,classes,Controls,
consts,Windows,Sysutils,forms;
Type
TRepOpenDialog = class(TOpenDialog)
private
FCheckPanel: TPanel;
FChkDrawHLine:TCheckBox;
FChkDrawVLine:TCheckBox;
protected
procedure DoClose; override;
procedure DoShow; override;
published
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
procedure Register;
implementation
constructor TRepOpenDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCheckPanel := TPanel.Create(Self);
with FCheckPanel do
begin
Name := 'CheckPanel';
Caption := '';
SetBounds(204, 5, 169, 200);
BevelOuter := bvNone;
BorderWidth := 6;
TabOrder := 1;
FChkDrawHLine := TCheckBox.Create(Self);
FChkDrawVLine := TCheckBox.Create(Self);
with FChkDrawHLine do
begin
Name := 'ChkDrawHLine';
Caption := '';
SetBounds(6, 6, 157, 23);
Align := alTop;
AutoSize := False;
Parent := FCheckPanel;
end;
with FChkDrawVLine do
begin
Name := 'ChkDrawVLine';
Caption := '';
SetBounds(6, 6, 157, 23);
Align := alTop;
AutoSize := False;
Parent := FCheckPanel;
end;
end;
end;
destructor TRepOpenDialog.Destroy;
begin
FChkDrawHLine.Free;
FChkDrawVLine.Free;
FCheckPanel.Free;
inherited Destroy;
end;
procedure TRepOpenDialog.DoClose;
begin
inherited DoClose;
{ Hide any hint windows left behind }
Application.HideHint;
end;
procedure TRepOpenDialog.DoShow;
var
PreviewRect, StaticRect: TRect;
begin
{ Set preview area to entire dialog }
GetClientRect(Handle, PreviewRect);
StaticRect := GetStaticRect;
{ Move preview area to right of static area }
PreviewRect.Left := StaticRect.Left + (StaticRect.Right - StaticRect.Left);
Inc(PreviewRect.Top, 4);
FCheckPanel.BoundsRect := PreviewRect;
FCheckPanel.ParentWindow := Handle;
inherited DoShow;
end;
procedure Register;
begin
RegisterComponents('Standard', [TRepOpenDialog]);
end;
end.