我试图更改类中标签的文本,但没有成功。
我所拥有的是我使用 get{} 和 set{} 更新类中的变量。我知道我需要在 set{} 中放置或执行某些操作,以使其将更新值从类发送回 form1 类,以便它可以更新标签。
谁能告诉我如何才能做到这一点?或者如果有一种方法可以从类内更新标签,那就更好了。
我希望这是有道理的,并提前致谢。
我不完全确定我的所有术语是否正确,如果我错了,请原谅我.我想知道是否可以向方法发送一个参数.以下面的例子为例.
public item (int index)
{
get { return list[index]; }
set { list[index] = value; }
}
Run Code Online (Sandbox Code Playgroud)
我知道原样,它会出错.我要问的是,是否有某种方法可以让它发挥作用.有什么建议或者我应该找出一些方法吗?
提前致谢.
我有一个自定义表单,将值返回到主窗体,但它没有看到变量.我不认为我这么说清楚,所以我将包含我想要做的例子的链接.
我知道我可能会忽略一些非常简单或明显的东西,但这就是我所拥有的.
Form1.cs中:
private void addTime_Click(object sender, EventArgs e)
{
Form add = new addTime(false, new string[] { "", "" });
if (add.ShowDialog(this) == DialogResult.OK)
{
// the line not working
Label1.Text = add.Details;
// reports with:'System.Windows.Forms.Form' does not contain a
// definition for 'Details' and no extension method 'Details' accepting
// a first argument of type 'System.Windows.Forms.Form' could be found (are you
// missing a using directive or an assembly reference?)
}
}
Run Code Online (Sandbox Code Playgroud)
addTime.cs:
internal class addTime …Run Code Online (Sandbox Code Playgroud)