[英]Visual Studio 2012 Windows Form application
I am working on Windows Form application on Visual Studio 2012. I have 2 forms. 我正在Visual Studio 2012上的Windows窗体应用程序上工作。我有2个窗体。
Add_Item_to_DB1
Add_Item_to_DB2
Both of these forms call a third form called SUBMIT
. 这两种形式都称为第三种形式,称为SUBMIT
。 Now, based on where this form is being called from, it has to submit information to a different database. 现在,根据调用此表单的位置,它必须将信息提交到其他数据库。 Everything else in the SUBMIT
form is EXACTLY the same except, data is inserted to a different database. SUBMIT
表单中的所有其他内容完全相同,除了将数据插入到其他数据库中。
Is there a way to find out where the form is being called from? 有没有办法找出从何处调用表单? Kinda new to Form applications. Kinda是Form应用程序的新功能。
Thank you 谢谢
If you open the SUBMIT form with the ShowDialog()
method you will be able to determine the form that opened the SUBMIT form via the Owner
property. 如果使用ShowDialog()
方法打开SUBMIT表单,则可以通过Owner
属性确定打开SUBMIT表单的表单。 For example: 例如:
public partial class Add_Owner_To_Db_1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
var submitForm = new SUBMIT();
submitForm.ShowDialog(this);
}
}
public partial class SUBMIT : Form
{
private void SUBMIT_Load(object sender, EventArgs e)
{
//label1.Text will equal "Add_Owner_To_Db_1"
label1.Text = this.Owner.Text;
}
}
Alternatively you can expose a public property on your SUBMIT form that can be populated from the parent form. 或者,您可以在SUBMIT表单上公开一个公共属性,该公共属性可以从父表单中填充。 For example: 例如:
public partial class Add_Owner_To_Db_1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
var submitForm = new SUBMIT();
submitForm.ParentName = "Add_Owner_To_Db_1";
submitForm.Show();
}
}
public partial class SUBMIT : Form
{
public string ParentName { get; set; }
private void SUBMIT_Load(object sender, EventArgs e)
{
//label1.Text will equal "Add_Owner_To_Db_1"
label1.Text = ParentName;
}
}
HTH HTH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.