1、改写CreateParams
unit Anchor;
interface
uses
; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
; StdCtrls;
type
; TAnchorForm = class(TForm)
; private
; ; FParentForm : TForm;
; protected
; ; procedure CreateParams(VAR Params: TCreateParams); override;
; public
; ; property ParentForm :TForm read FParentForm write FParentForm;
; ; constructor Create(Sender: TComponent);override;
; end;
var
; AnchorForm: TAnchorForm;
implementation
{$R *.DFM}
constructor TAnchorForm.Create(Sender:TComponent);
begin
; if Sender is TForm then
; ; FParentForm := Sender as TForm
; else
; ; FParentForm := nil;
; inherited Create(Sender);
end;
procedure TAnchorForm.CreateParams(VAR Params: TCreateParams);
begin
; Inherited CreateParams(Params);
; if assigned(FParentForm) then
; ; Params.WndParent := FParentForm.Handle;
end;
end.
创建的时候,
with TAnchorForm.Create(ParentForm) do
; ShowModal;
就一定会放在ParentForm上面,不会被其他窗口遮住。
你也可以将TAnchorForm作为父类,你的其他窗口从它继承,
省得每次都写CreateParams过程。
2、用
MessageBox(ParentForm.Handle,...)不要用
Application.MessageBox。