求助有关MDI子窗体控制问题(50分)

  • 主题发起人 主题发起人 jian23cn
  • 开始时间 开始时间
J

jian23cn

Unregistered / Unconfirmed
GUEST, unregistred user!
我想判断主窗体(Fomr1)中是否含有子窗体(Form2),如果存在则把它关闭,如果不存在则动态创建。请问是否有可能实现?如果用FindWindowEx来查找那我应该怎么写?谢谢~!
 
&nbsp; &nbsp;if &nbsp;Form2 = nil then<br>&nbsp; &nbsp; &nbsp; &nbsp;Application.CreateForm(TForm, Form2);<br>&nbsp; &nbsp;else <br>&nbsp; &nbsp; &nbsp; &nbsp;close;<br>&nbsp;
 
给个通用过程,不管是不是MDI窗体都行<br>procedure OpenForm(FormClass: TFormClass; var AForm;<br>&nbsp; &nbsp; AOwner:TComponent=nil);<br>//根据窗口类名建立窗口,如果窗口存在则只激活它<br>var<br>&nbsp; i: integer;<br>&nbsp; Child:TForm;<br>begin<br>&nbsp; for i := 0 to Screen.FormCount -1 do<br>&nbsp; &nbsp; &nbsp; if Screen.Forms.ClassType=FormClass then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Child:=Screen.Forms;<br>&nbsp; &nbsp; &nbsp; &nbsp; if Child.WindowState=wsMinimized then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Child.WindowState:=wsNormal;<br>&nbsp; &nbsp; &nbsp; &nbsp; Child.BringToFront;<br>&nbsp; &nbsp; &nbsp; &nbsp; Child.Setfocus;<br>&nbsp; &nbsp; &nbsp; &nbsp; TForm(AForm):=Child;<br>&nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; Child:=TForm(FormClass.NewInstance);<br>&nbsp; TForm(AForm):=Child;<br>&nbsp; if not assigned(aowner) then aowner:=application;<br>&nbsp; Child.Create(AOwner);<br>end;<br>建立用<br>OpenForm(Tydcx_frm,ydcx_frm,self);<br>窗口关闭还是<br>procedure Tydcx_frm.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; action:=cafree;<br>end; <br>
 
回:多情剑客无情剑 &nbsp;大哥<br>用你的方法第一次是可以,但在第二次时会提示出错,应该怎么改进?谢谢~!<br>回:cwmdelpher 大哥<br>如果窗体存在时我想把它关闭,应该怎么改?谢谢~!
 
调用子窗体<br>if Assigned(Form2) then Application.CreateForm(TForm2,Form2);<br><br>子窗体的Close事件中<br>Action:=caFree;<br>子窗体的Destroy事件中<br>Form2:=nil;<br>
 
问题已经解决了,谢谢各位~!
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
916
SUNSTONE的Delphi笔记
S
后退
顶部