不可访问 因为它受保护级别限制!! (转)

开始学习C#
我建立了2个FORM
FORM1 HE FORM2
在调试的时候包了一个错误
C:\Documents and Settings\Administrator\My Documents\c\WindowsApplication6\Form1.cs(130): 不可访问“WindowsApplication6.Form2.label1”,因为它受保护级别限制
具体 错误行见下面
yourForm.label1.Font=new Font("宋体",16);
   yourForm.label1.BackColor=Color.Aqua;
   yourForm.label1.Text="这是窗体2 ";

网上查找 了一下!大概是private和public的问题
private是私有变量
public是共有变量
在FORM 2里面的
public class Form2 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button button1;
 private System.Windows.Forms.Label label1;

把private System.Windows.Forms.Label label1;修改为public System.Windows.Forms.Label label1;
就OK 了!
原文地址:https://www.cnblogs.com/it563/p/584328.html