Nyi*_*ght 1 c# visual-studio-2008
我有一个自定义表单,将值返回到主窗体,但它没有看到变量.我不认为我这么说清楚,所以我将包含我想要做的例子的链接.
我知道我可能会忽略一些非常简单或明显的东西,但这就是我所拥有的.
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 : Form
{
//..
private string _details;
public string Details
{
get { return _details; }
private set { _details = value; }
}
private string _goalTime;
public string GoalTime
{
get { return _goalTime; }
private set { _goalTime = value; }
}
private void applybtn_Click(object sender, EventArgs e)
{
Details = detailslbl.Text;
GoalTime = goalTimelbl.Text;
}
}
Run Code Online (Sandbox Code Playgroud)
您的"添加"变量的类型为Form,而不是addTime,而Form类型没有Details属性.
请尝试这一行:
addTime add = new addTime(false, new string[] { "", "" });
Run Code Online (Sandbox Code Playgroud)