Panel无法在MDI中设置Visible True [英] Panel Could not set Visible True in MDI

查看:80
本文介绍了Panel无法在MDI中设置Visible True的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

i我正在使用C#.Net Windows应用程序..我有一个MDI父表单和许多Child Form..i把面板放在MDI父表单中并在面板中拖动几个按钮..

当我点击按钮时,他们打开另一个子窗体并将可见假设置为面板

就像这个示例代码一样,

Hi Friends,
i am using C#.Net Windows Application..I have one MDI Parent Form and many Child Form..i put panel in MDI Parent Form and Drag Several Button inside Panel..
When i click the Button they open Another Child Form and Set Visible false to Panel
like this Sample Code,

private void Button_Click(object sender, EventArgs e)
        {
            panel1.Visible = false;
            ChildForm Form2 = new ChildForm ();           
            Form2 .WindowState = FormWindowState.Maximized;           
            Form2 .Show();
            
        }



现在他们完美地工作..问题是,当我关闭Childform时,面板在MDI父窗体中无法显示。 .its总是面板可见false..i设置为true看到我的代码..




Now they Perfectly Working..wht the Problem is, when i close the Childform the panel could not Visible in MDI Parent Form..its always panel visible false..i set to true see my code..

private void ChildForm _FormClosed(object sender, FormClosedEventArgs e)
       {
                this.Dispose();
                MDI md = new MDI();
                md.panel1.Visible = true;

       }



我也使用BringToFront,SendToBack ..No使用......

请协助......


am also using BringToFront,SendToBack..No Use...
Please Assist...

推荐答案

您正在做的是违背MDI功能的设计目标。我非常怀疑你根本不需要使用MDI。



但是,问题是你哄骗了 this.Dispose 在您的子表单上,然后您希望在它之后运行更多代码。对不起,但这不会按预期工作。您不能在Dispose语句之后处理表单(及其代码)并获得代码的可预测结果。一旦你在表单上调用Dispose,请考虑表单已死且无法使用。



我非常怀疑您的MDI类是父表单,您正在创建一个新实例当您关闭MDIChild表单时此代码不执行任何操作,因为当子窗体消失时,您创建的新MDI实例将被销毁。



您没有修改已在运行的实例你的MDI表格。你正在创建一个新的,修改它,从不显示它,然后立即忘记它。



你的代码没有按照你的想法做到因为你对自己的代码中发生的事情,事情是如何工作以及缺乏对面向对象编程基础知识的理解存在严重的误解。
What you're doing is going against what the MDI functionality was designed for. I heavily suspect that you don't need to use MDI at all.

But, the problem is that you caled this.Dispose on your child form and then you expected more code to run after it. Sorry, but that's not going to work as expected. You cannot dispose the form (and the code with it) and get predicatble results for the code after the Dispose statement. Once you call Dispose on a Form, consider the Form dead and unusable.

I highly suspect that your MDI class is a parent form that you're making a new instance of when you close the MDIChild form. This code doesn't do anything as the new instance of MDI that you created is detroyed when the child form goes away.

You're not modifying the already running instance of your MDI form. You're creating a new one, modifying it, never showing it, and then immediately forgetting about it.

Your code does doesn't do what you think it does because you have serious misconceptions about what is going on in your own code, how things work, and a lack of understanding of the basics of Object Oriented Programming.


用于form1()

{

use for form1()
{
//panel1.Visible = false;
this.Hide();
//this.Dispose();
Form2 f = new Form2();
f.WindowState = FormWindowState.Maximized;
f.Show();









}


$ 2 $ b用于Form2()

{







}

use for Form2()
{

this.Dispose();
Form1 f = new Form1();
f.Visible = true;







}




}


尝试以下代码

Try below code
private void Button_Click(object sender, EventArgs e)
        {
            panel1.Visible = false;
            ChildForm Form2 = new ChildForm (); 
            Form2.MdiParent = this; 
            Form2.WindowState = FormWindowState.Maximized;           
            Form2.Show();
            
        }







private void ChildForm _FormClosed(object sender, FormClosedEventArgs e)
       {
                MDI mdiParent =(MDIParent1)this.MdiParent;
                mdiParent.panel1.Visible = true;
                this.Dispose();
       }


这篇关于Panel无法在MDI中设置Visible True的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆