Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从一个窗体设置另一个窗体中按钮的visible属性_C#_.net_Winforms_Button - Fatal编程技术网

C# 无法从一个窗体设置另一个窗体中按钮的visible属性

C# 无法从一个窗体设置另一个窗体中按钮的visible属性,c#,.net,winforms,button,C#,.net,Winforms,Button,我需要与其他表单上的控件交互。正在尝试使用以下命令访问控件,例如 我正在从form2访问Backupform控件 在backupform中:我定义如下 public partial class BackupForm { public bool ControlIsVisible { get { return this.btnrestore.Visible; } set {this.btnrestore.Visible = value; } } public BackupForm(

我需要与其他表单上的控件交互。正在尝试使用以下命令访问控件,例如

我正在从form2访问Backupform控件

在backupform中:我定义如下

public partial class BackupForm
{
 public bool ControlIsVisible
 {
  get { return this.btnrestore.Visible; }
  set {this.btnrestore.Visible = value; }
 }

 public BackupForm()
 {

  InitializeComponent();
  cbbackupforms.SelectedIndex = 0;
 // btnrestore.Enabled = false;
 }
}
我使btnrestore属性
visible=true
修饰符=private

在表格2中,我正在访问btnrestore visible属性

public partial class form2
{
  private Forms.BackupForm backs;

 public form2()
 {

  InitializeComponent();
  backs =  new Forms.BackupForm();
 }

 public void restore()
 {
      backs.ControlIsVisible = false;
 }  
}
但我无法看到按钮的错误,请任何人提出任何解决方案


非常感谢您提前提供对第一个表单实例的引用,并使用该引用设置该表单上对象的属性。将对象强制转换为Form1时,属性将可访问。

您可以提供对第一个表单实例的引用,并使用该引用设置该表单上对象的属性。将对象强制转换为Form1时,属性将可访问。

何时调用Restore()方法?另外,如果Restore()方法所做的一切都是在单独的表单上设置按钮的visible属性,为什么不将该方法封装在BackupForm对象中,并使用backs.Restore()调用它?

何时调用Restore()方法?另外,如果Restore()方法所做的只是在单独的表单上设置按钮的visible属性,为什么不将该方法封装在BackupForm对象中,并使用backs.Restore()调用它呢?

只是为了确保,您是否真的调用了“Restore”方法?我确信……我正在调用Restore方法……无法重现它。问题是没有调用“还原”或其他方法。只是为了确定,您是否真的调用了“还原”方法?我确信……我正在调用还原方法……无法复制它。问题是要么不调用“还原”,要么其他什么。