能见度不变 [英] visibility not changing

查看:86
本文介绍了能见度不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我隐藏了表单开口处的关闭按钮,并希望在关闭时再次显示它......它隐藏得很完美但不会变得可见

父表单代码:< br $>


i hide the shut down button on the opening of a form and want to make it visible again when it closes.....its hiding perfectly bt not becoming visible
parent form code:

private void studentRegisterationToolStripMenuItem_Click(object sender, EventArgs e)
       {
           shutDownToolStripMenuItem.Visible = false;
           Student_Registeration sr = new Student_Registeration();
           sr.MdiParent=this;
           sr.Show();
       }      
       public void shutShow()
       {
           shutDownToolStripMenuItem.Visible = true;
       }







儿童表格代码






child form code

private void close_button_Click(object sender, EventArgs e)
      {
          Form1 f1 = new Form1();
          f1.shutShow();
          this.Close();
      }

推荐答案

首先,阅读所有评论。



其次,你有两种可能性:

1)委托(C#) [ ^ ] - 委托是引用方法的类型。为委托分配方法后,其行为与该方法完全相同。委托方法可以像任何其他方法一样使用,带有参数和返回值。

在Windows窗体之间传递数据 [ ^ ]



2)界面(C#) [ ^ ] - 一个接口只包含方法,委托或事件的签名,方法的实现在类中完成实现界面。

C#中的接口构造 [ ^ ]
First of all, read all comments.

Second, you have 2 possibilities:
1) Delegate (C#)[^] - A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value.
Passing Data between Windows Forms[^]

2) Interface (C#)[^] - An interface contains only the signatures of methods, delegates or events, the implementation of the methods is done in the class that implements the interface.
The Interface Construct in C#[^]


已发布以关闭此问题。



这是因为您正在创建一个新的Form1的实例并显示按钮,然后您新创建的实例超出范围并被销毁。所以你永远不会看到它真的发生了。



您需要将Form1的现有实例传递给子表单,或者按照Sergey的建议并创建一个接口传递给表单。谢尔盖的建议更倾向于OOP,并且是首选方法。
Posted to close the issue.

That is because you are creating a new instance of Form1 and showing the button, then your newly created instance is going out of scope and destroyed. So you would never, ever see it actually happen.

You either need to pass the existing instance of your Form1 to the "child" form, or do as Sergey suggests and create an interface to pass to the form. Sergey''s suggestion is more OOP oriented and would be the preferred method.


这篇关于能见度不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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