我想在按下一个button时,改变类里面一个值,然后通过这个值来改变text的值来显示出来
例如:按下button1的时候,fact.true=1,相应的 ,label.text中的值变为"回答正确!"
该如何定义fact,使他和button和label有这样的联系啊,fact需要是一个单独的cs文件
还有,我使用label.text="回答正确",的时候显示运行错误,"C:\Documents and Settings\aaa\My Documents\Visual Studio Projects\Project1\Form1.cs(138): 不可访问“System.Windows.Forms.Control.text”,因为它受保护级别限制"出来这句话,该怎么改啊我是新手,请别用那些专业语言回答,谢谢
例如:按下button1的时候,fact.true=1,相应的 ,label.text中的值变为"回答正确!"
该如何定义fact,使他和button和label有这样的联系啊,fact需要是一个单独的cs文件
还有,我使用label.text="回答正确",的时候显示运行错误,"C:\Documents and Settings\aaa\My Documents\Visual Studio Projects\Project1\Form1.cs(138): 不可访问“System.Windows.Forms.Control.text”,因为它受保护级别限制"出来这句话,该怎么改啊我是新手,请别用那些专业语言回答,谢谢
第二个问题我猜测可能你是在两个窗体之间调用的,如果你想再Form2中调用Form1的变量,可以用两种办法,一是通过构造函数传递,再有就是将Form1的变量的修饰类型改成 public 的
{
private bool _Clicked;
public bool clicked
{
get { return _Clicked; }
set
{
_Clicked = value;
}
} private string _GetText;
public string getText
{
get
{ if (_Clicked)
{
_GetText = "回答正确";
}
else
{
_GetText = "回答错误";
} return _GetText;
} }
}
public partial class Form3 : Form
{
BindingSource bindingSource1 = new BindingSource();
public Form3()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
fact _fact=new fact();
_fact.clicked=true;
bindingSource1.Add(_fact);
label1.DataBindings.Add("Text", bindingSource1, "getText");
}
}