关于winform的MID窗体

flashasp 2007-05-18 09:29:04
我在winform的MID窗体的菜单中这样跳到新的子窗体,为何子窗体上的控件一个都看不到呢
private void FileNew_Click(object sender, System.EventArgs e)
{

Form FrmTest=new Form();
FrmTest.ShowDialog();
}
...全文
334 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
flashasp 2007-05-18
  • 打赏
  • 举报
回复
没这么复杂吧,还要写函数
wwlprince 2007-05-18
  • 打赏
  • 举报
回复
错了,调用函数为
Form1 fm=new Form1();
OpenWindow( typeof(Form1).ToString() );
wwlprince 2007-05-18
  • 打赏
  • 举报
回复
//首先是通过子窗体类型名来判断是否打开新的子窗体,还是把原有的子窗体进行显示。
// Open child window
private void OpenWindow( string ChildTypeString )
{
Form myChild = null;
if( !ContainMDIChild( ChildTypeString ) )
{
// Get current process assembly
Assembly assembly = Assembly.GetExecutingAssembly();
// Create data type using type string
Type typForm = assembly.GetType( ChildTypeString );
// Create object using type's "InvokeMember" method
Object obj = typForm.InvokeMember(
null,
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.CreateInstance,
null,
null,
null );
// Show child form
if( obj != null )
{
myChild = obj as Form;
myChild.MdiParent = this;
myChild.Show();
myChild.Focus();
}
}
}
/// Search mdi child form by specific type string
private bool ContainMDIChild( string ChildTypeString )
{
Form myMDIChild = null;
foreach(Form f in this.MdiChildren)
{
if( f.GetType().ToString() == ChildTypeString )
{
// found it
myMDIChild = f;
break;
}
else
{
f.Close();
}
}
// Show the exist form
if( myMDIChild != null)
{
myMDIChild.TopMost = true;
myMDIChild.Show();
myMDIChild.Focus();
return true;
}
else
return false;
}
在你点击的事件中调用下面函数就行
Form1 fm=new Form1();
OpenWindow( typeof(Formsjwh1).ToString() );
flashasp 2007-05-18
  • 打赏
  • 举报
回复
我这样搞可以哦
Frm.FrmTest f=new Frm.FrmTest();
f.MdiParent=this;
f.Show();

但是每次点一次就出来一个同样的窗体,怎么解决呢??
patrickpan 2007-05-18
  • 打赏
  • 举报
回复
Form FrmTest=new Form();
把Form改成你子窗体的类名

ChildForm frmTest = new ChildForm();
其中ChildForm是你子窗体类的名称.

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧