c#,form打开新子窗口关闭旧其他子窗口

本文展示了如何在C#中使用FormCollection来遍历并关闭所有非当前活动的子窗口,以及如何在特定事件触发时(如按键事件),设置新窗口为MDI容器并传递参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

部分代码:

            //关闭其他窗口
            FormCollection childCollection = Application.OpenForms;
            for (int i = childCollection.Count; i-- > 0;)
            {
                if (childCollection[i] != this)
                    childCollection[i].Close();
                else
                    break;
            }

按键实现:

        private void t10chapwd_Click(object sender, EventArgs e)
        {
            //关闭其他窗口
            FormCollection childCollection = Application.OpenForms;
            for (int i = childCollection.Count; i-- > 0;)
            {
                if (childCollection[i] != this)
                    childCollection[i].Close();
                else
                    break;
            }

            this.IsMdiContainer = true;
            change_the_password chapwd = new change_the_password();
            chapwd.MdiParent = this;//this新窗口的父窗口
            chapwd.userno3 = userno1;//传参
            chapwd.Show();   
        }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值