我有一个表单中包含一些元素。我想从我的主窗口访问该表单中的数据。我试着做以下几点:从另一个表单访问属性
private void EmailSettings_Load(object sender, EventArgs e)
{
textBox1.Text = Properties.Settings.Default.emailServer;
numericUpDown1.Value = Properties.Settings.Default.emailServerPort;
if (Properties.Settings.Default.emailServerSsl == true)
{
radioButton1.Checked = true;
}
else
{
radioButton1.Checked = false;
}
}
不过,我的问题是,我无法从我的主要形式访问Properties
:
private void button1_Click(object sender, EventArgs e)
{
Properties.Settings.Default.emailServer = textBox1.Text;
Properties.Settings.Default.emailServerPort = (int)numericUpDown1.Value;
Properties.Settings.Default.emailServerSsl = (radioButton1.Checked == true) ? true : false;
Properties.Settings.Default.Save();
this.Close();
}
我可以使用此代码加载它完全正常的存在形式。所以我仍然无法访问该表单中的数据。我如何从我的主表单中的属性或从其他表单访问数据?
看这里:http://stackoverflow.com/questions/35897399/access-variables-between-cs-files-in-wpf-c-sharp/35897626#35897626 ...这正是你的问题。 – Fruchtzwerg