var f: TfrmUserPower; I: Integer; begin for i := 0 to Panel.ControlCount - 1 do begin if Panel9.Controls[i].InheritsFrom (TfrmUserPower) then begin f := TfrmUserPower(Panel.Controls[i]); Panel.RemoveControl(f); freeAndNil(f); end; end; F := TfrmUserPower.Create(Panel); Panel.DockSite := True; with F do begin DockSite := True; DragKind := DkDock; Align := alClient; HostDockSite := Panel; Show; end; end;
Windows.SetParent
就可!
SetProp(ih, 'OldParent', GetParent(ih));
Windows.SetParent(ih, TabSheet2.Handle); Style := GetWindowLong(ih, GWL_STYLE);
StyleEx := GetWindowLong(ih, GWL_EXSTYLE);
SetProp(ih, 'OldStyle', Style);
SetProp(ih, 'OldStyleEx', StyleEx); SetWindowLong(ih, GWL_STYLE, ((Style or WS_CHILD) and not (WS_POPUP or WS_BORDER)));
SetWindowLong(ih, GWL_EXSTYLE, ((Style or WS_EX_CONTROLPARENT)));
SetWindowPos(ih, HWND_TOP, 2, 2, 0, 0, SWP_SHOWWINDOW or SWP_NOSIZE); ShowWindow(ih, SW_SHOWMAXIMIZED);得到你的Panel.handle 和窗體的Handle 就可!
我的例子是設置到 TabSheet2 上的
frmCInfoQuery.BorderStyle := bsNone;
frmCInfoQuery.Align := alClient;
Windows.SetParent(frmCInfoQuery.Handle, parent);
frmCInfoQuery.Show;
f: TfrmUserPower;
I: Integer;
begin
for i := 0 to Panel.ControlCount - 1 do
begin
if Panel9.Controls[i].InheritsFrom (TfrmUserPower) then
begin
f := TfrmUserPower(Panel.Controls[i]);
Panel.RemoveControl(f);
freeAndNil(f);
end;
end;
F := TfrmUserPower.Create(Panel);
Panel.DockSite := True;
with F do
begin
DockSite := True;
DragKind := DkDock;
Align := alClient;
HostDockSite := Panel;
Show;
end;
end;