简体   繁体   English

Visual Studio 2012 Windows窗体应用程序

[英]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.

相关问题 Visual Studio 2012构建Windows 10应用程序? - Visual Studio 2012 build application for windows 10? Windows Form Application C锐视觉工作室2010 - Windows Form Application C sharp visual studio 2010 在Visual Studio 2015中是否有ac#windows form应用程序? - Is there a c# windows form Application in visual Studio 2015? Visual Studio - 以参数为输入的 windows 表单应用程序的设置项目 - Visual studio - Setup project for windows form application with a parameter as input 在其他窗口处于活动状态时,Visual Studio-Windows窗体应用程序中的快捷方式 - Shortcut in Visual Studio - Windows Form Application while other Window is active 在Visual Studio 2010/2012中发布应用程序 - Publishing an application in Visual Studio 2010/2012 如何使Visual Studio 2012从Windows窗体设计生成代码? - How do I get Visual Studio 2012 to generate code from a windows form design? 在Visual Studio 2012中使用SqlServer 2012 Databse部署Windowsform应用程序 - Deploying Windowsform application with SqlServer 2012 Databse in Visual Studio 2012 在Visual Studio 2010 Professional for C ++ Windows窗体应用程序下更改启动窗体 - Change startup form under Visual Studio 2010 Professional for C++ Windows Form Application Visual Studio Express 2012,没有适用于 C++ 的 Windows 窗体? - Visual Studio Express 2012, no Windows Forms for C++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM