var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
//把Form2的Parent改為Form1
Form2 := TForm2.CreateParented(Form1.Handle);
Form2.Show;
//使得Form2處於激活狀態
SendMessage(Form2.Handle, WM_NCACTIVATE, Ord(True), 0);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form2.Close;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
//記得加上這一句
if Form2.Showing then Form2.Close;
end;
end.
上面的代碼就可以顯示一個與Form1同處激活狀態的Form2,再對Form2的BorderStyle與BorderIcons屬性作一些必要的選擇,就可以實現更加完美的效果!