控件问题。(100分)

  • 主题发起人 主题发起人 wpw72
  • 开始时间 开始时间
W

wpw72

Unregistered / Unconfirmed
GUEST, unregistred user!
我要做个控件,从wincontrol继承,创建4个panel,代码如下
unit CPanel;
interface
uses
SysUtils, Classes, Controls, ExtCtrls, messages;
type
TCPanel = class(TWinControl)
private
FPanel1: TPanel;
FPanel2: TPanel;
FPanel3: TPanel;
FPanel4: TPanel;
FVisiblePanelCount: SmallInt;
procedure FSetVisiblePanelCount(Avalue: SmallInt);
protected
procedure WMSize(var MSG: TMessage);
message WM_SIZE;
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
published
property VisiblePanelCount: SmallInt read FVisiblePanelCount write
FSetVisiblePanelCount;
end;

procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TCPanel]);
end;

constructor TCPanel.Create(AOwner: TComponent);
begin
inherited;
FVisiblePanelCount := 4;
FPanel1 := TPanel.Create(nil);
with FPanel1do
begin
Parent := Self;
Top := 0;
Left := 0;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
Caption := 'pnl1';
end;
FPanel2 := TPanel.Create(nil);
with FPanel2do
begin
Parent := Self;
Top := 0;
Left := FPanel1.Width;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
Caption := 'pnl2';
end;
FPanel3 := TPanel.Create(nil);
with FPanel3do
begin
Parent := Self;
Top := 0;
Left := FPanel2.Left + FPanel2.Width;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
Caption := 'pnl3';
end;
FPanel4 := TPanel.Create(nil);
with FPanel4do
begin
Parent := Self;
Top := 0;
Left := FPanel3.Left + FPanel3.Width;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
Caption := 'pnl4';
end;
end;

destructor TCPanel.destroy;
begin
FPanel1.Free;
FPanel2.Free;
FPanel3.Free;
FPanel4.Free;
inherited;
end;

procedure TCPanel.WMSize(var MSG: TMessage);
begin
with FPanel1do
begin
Left := 0;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
end;
with FPanel2do
begin
Left := FPanel1.Width;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
end;
with FPanel3do
begin
Left := FPanel2.Left + FPanel2.Width;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
end;
with FPanel4do
begin
Left := FPanel3.Left + FPanel3.Width;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
end;
end;

procedure TCPanel.FSetVisiblePanelCount(Avalue: SmallInt);
begin
if Avalue in [1..4] then
FVisiblePanelCount := Avalue;
with FPanel1do
begin
Left := 0;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
end;
with FPanel2do
begin
Left := FPanel1.Width;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
end;
with FPanel3do
begin
Left := FPanel2.Left + FPanel2.Width;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
end;
with FPanel4do
begin
Left := FPanel3.Left + FPanel3.Width;
Height := Parent.Height;
Width := Parent.Width div FVisiblePanelCount;
end;
end;

end.
现在我的控件放到form上后,无法向panel上放其他控件。
 
你不能直接创建里面的控件,包含的4个TPanel要等运行后创建。
 
后退
顶部