it563
开始学习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 了!

分类:

技术点:

相关文章:

  • 2021-09-03
  • 2021-10-24
  • 2021-11-11
  • 2022-02-02
  • 2021-05-20
  • 2022-02-08
  • 2021-10-25
  • 2022-12-23
猜你喜欢
  • 2021-11-04
  • 2022-12-23
  • 2021-06-13
  • 2021-10-14
  • 2021-11-01
  • 2021-12-22
  • 2022-12-23
相关资源
相似解决方案