求:俩个窗体同时显示问题 (必须showmodal)
要求:程序一运行时俩窗体同时显示(子窗体显示在前面),这点已做到;现在子窗体有一button1要求显示主窗体(已存在则直接显示)我现在的问题是:点button1时显示主窗体子窗体没法关闭(其实是主窗体FormCreate中又创建了一次);看看吧或许描述的不清,代码明了:
mainFrom:
const WM_MYMSG=WM_APP+1;
procedure WMMYMSG( var msg:Tmessage); message WM_MYMSG;
end;
var
MainForm: TMainForm;
implementation
uses unit2,Unit3;
{$R *.dfm}
procedure TMainForm.WMMYMSG( var msg:Tmessage);
var
f:TForm1;
begin
f:=TForm1.create(nil);
f.ShowModal;
end;
procedure TMainForm.FormCreate(Sender: TObject);
var
f:TForm1;
begin
PostMessage(Handle,WM_MYMSG,0,0);
end;
子窗体:
procedure TForm1.Button1Click(Sender: TObject);
var
f:TMainForm;
begin
try
if not Assigned(f) then
begin
f:=TMainForm.Create(self);
f.Show;
end;
finally
if Form1<>nil then
freeandnil(Form1);
end;
end;
end.
[解决办法]
没做过 帮你定下吧
[解决办法]
为什么主窗体要重新创建,按理说主窗体关闭了,整个程序都会关闭的
何况你的Button1Click代码造成循环了,创建MainForm时会重新PostMessage,又创建Form1
只改变他们的hide,show就行了
procedure TForm1.Button1Click(Sender: TObject);
begin
MainForm.show;
freeandnil(Form1); //或者可以考虑用Form1.hide
end;
[解决办法]
牛逼
典型的死循环的嘛
[解决办法]
Use ShowModal to show a form as a modal form. A modal form is one where the application can continue to run until the form is closed. Thus, ShowModal does not return until the form closes. When the form closes, it returns the value of the ModalResult property.