应用程序中隐藏和显示表单

应用程序中隐藏和显示表单

本文介绍了在 WinForms 应用程序中隐藏和显示表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
Winform 表单关闭和打开新表单

在我的 Windows 应用程序中,我有两种形式;表单1和表单2

In my windows application I have two forms; form1 and form2

在 form1 中,我使用以下处理程序监听按钮单击,

In form1 I listen to a button click with the following handler,

private void btn1_Click(object sender, EventArgs e)
{
    Form2 updatewindow = new Form2();
    updatewindow.Show();
}

在 Form2 中,我想单击一个按钮并显示第一个表单 form1,因此 form2 中的按钮单击处理程序执行以下操作

In Form2 I want to click on a button and show the first form, form1, so the button click handler in form2 does the following

private void btn2_Click(object sender, EventArgs e)
{
    try
        {

            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "codedata.xml");
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            XmlNodeList nodelist = doc.SelectNodes("Root/data[Sno='" + getsnofromform1 + "']");
            nodelist[0].ChildNodes[2].InnerText = txt_productcodeupdate.Text;
            nodelist[0].ChildNodes[3].InnerText = txt_productnameupdate.Text;
            nodelist[0].ChildNodes[4].InnerText = txt_brandcodeupdate.Text;
            nodelist[0].ChildNodes[5].InnerText = txt_brandnameupdate.Text;
            doc.Save(path);
            MessageBox.Show("Selected Record Updated Successfully");

        }
        catch
        {
        }
        finally
        {
            //txt_sno.Text = "";
            // txt_companycode.Text = "";
            txt_productcodeupdate.Text = "";
            txt_productnameupdate.Text = "";
            txt_brandcodeupdate.Text = "";
            txt_brandnameupdate.Text = "";

            BarcodeCount form1 = new BarcodeCount();
            form1.BringToFront();
            form1.Invalidate();
            Application.OpenForms["BarcodeCount"].Refresh();
            this.Close();
        }
}

问题是我想显示旧表单,但打开了一个新的 Form1 窗口.

The problem is I want to display the old form, but instead a new Form1 window is opening.

我想刷新form1 form form2

i want to refresh the form1 form form2

推荐答案

FormName x = default(FormName);
x = new FormName();
x.Show();
x = null;

x 在需要时为 Form1 或 Form2.

x being either Form1 or Form2 when needed.

这篇关于在 WinForms 应用程序中隐藏和显示表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 02:26