Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 页面加载时打开的两个窗口_C#_Asp.net_Winforms_Windows Applications - Fatal编程技术网

C# 页面加载时打开的两个窗口

C# 页面加载时打开的两个窗口,c#,asp.net,winforms,windows-applications,C#,Asp.net,Winforms,Windows Applications,在Windows应用程序中,我正在创建两个表单,分别名为Form1和Configuration\u Form。首先,我正在加载配置表单。在这个表单中,我检查与txt文件的连接。如果txt文件有一些数据,这意味着它将加载Form1。 否则配置表单将不会加载任何内容 现在我有一个问题,假设txt文件有一些数据,那么这意味着它将加载Form1并打开另一个空表单。我只想显示表单1,而不是空表单。我怎样才能阻止那张空表格 这是我的部分代码: public partial class Confi

在Windows应用程序中,我正在创建两个表单,分别名为
Form1
Configuration\u Form
。首先,我正在加载
配置表单
。在这个表单中,我检查与txt文件的连接。如果txt文件有一些数据,这意味着它将加载
Form1
。 否则配置表单将不会加载任何内容

现在我有一个问题,假设txt文件有一些数据,那么这意味着它将加载
Form1
并打开另一个空表单。我只想显示
表单1
,而不是空表单。我怎样才能阻止那张空表格

这是我的部分代码:

      public partial class Configuration_Form : Form
{
    Form1 form = new Form1();
    public Configuration_Form()
    {
        StreamReader tr = new StreamReader(Application.StartupPath + "\\" + "config.txt");

        string config = tr.ReadToEnd();
        if (config.Replace("\r\n", string.Empty) == "")
        {
            tr.Close();
            InitializeComponent();
        }
        else
        {
            form.Show();
        }
    }
    ///////////////////////////
   private void btn_submit_Click(object sender, EventArgs e)
    {
        try
        {
            if ((txtIP.Text != "") && (txtdatabase.Text != "") && (txtuser.Text != "") && (txtpass.Text != ""))
            {
                StreamWriter sr = new StreamWriter(Application.StartupPath + "\\" + "config.txt");
                sr.Write(Convert.ToString((txtIP.Text) + ";" + (txtport.Text) + ";" + (txtdatabase.Text) + ";" + (txtuser.Text) + ";" + (txtpass.Text)));
                sr.WriteLine();
                sr.Close();
                this.Hide();
                form.Show();

            }
            else
            {
                DialogResult msg = MessageBox.Show("All are mandatory fileds!", "SBS-BIO-CONFIG Administrator", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                if (Convert.ToBoolean(msg) == true)
                {
                    this.Show();
                }
            }
        }
        catch (Exception e1)
        {
            MessageBox.Show("'" + e1.Message + "'");
        }
    }
以下是
表格1
代码:

    public partial class Form1 : Form
{

    MySqlConnection con;
    MySqlCommand cmd;
    MySqlDataAdapter DA;
    MySqlDataReader DR;
    DataSet DSS;

    #region Form_Load

    public Form1()
    {
        InitializeComponent();
    }
   namespace BIO_PUNCH_UPDATE
   {
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Configuration_Form());
    }
}
}
这是我的
程序.cs
代码:

    public partial class Form1 : Form
{

    MySqlConnection con;
    MySqlCommand cmd;
    MySqlDataAdapter DA;
    MySqlDataReader DR;
    DataSet DSS;

    #region Form_Load

    public Form1()
    {
        InitializeComponent();
    }
   namespace BIO_PUNCH_UPDATE
   {
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Configuration_Form());
    }
}
}
namespace BIO\u PUNCH\u更新
{
静态类程序
{
/// 
///应用程序的主要入口点。
/// 
[状态线程]
静态void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
运行(新配置表单());
}
}
}

请帮助我修复此错误。

我想您需要根据配置数据加载其中一个表单。如果是,则代码如下:

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Form form;

        StreamReader tr = new StreamReader(Application.StartupPath + "\\" + "config.txt");

        string config = tr.ReadToEnd();
        tr.Close();
        if (string.IsNullOrWhiteSpace(config))
        {
            form = new Configuration_Form();
        }
        else
        {
            form = new Form1();
        }

        Application.Run(form);
    }

另外,如果您需要其中一个表单中的配置数据,您可以将配置字符串作为构造函数参数传递。

是否在
Form\u Load
上加载数据?您所说的附加空表单是什么意思?
Form1
是在
btn\u submit\u Click
上打开还是在构造函数上打开?btn\u submit\u Click不是问题。假设config.text没有任何值意味着我从按钮单击事件加载数据。现在考虑CONTION文本有一些价值,首先它转到CudioType窗体并检查Copy.T正文。它有一些值,所以这次转到form1打开两个窗口,一个id form1,另一个是空表单。我怎样才能阻止空表单。。