Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8046597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:50:13+00:00 2026-06-05T05:50:13+00:00

In a Windows application, I’m creating two forms, named Form1 and Configuration_Form . First,

  • 0

In a Windows application, I’m creating two forms, named Form1 and Configuration_Form. First, I’m loading the Configuration_Form. In this form, I check the connection to a txt file. If the txt file has some data, it means that it will load Form1.
Otherwise Configuration_Form won’t load anything.

Now I have a problem, suppose the txt file has some data, then it means that it’s going to load Form1 and open another empty form. I want to show only the Form1, not the empty form. How can I block that empty form?

This is my partial code:

      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 + "'");
        }
    }

Here is the Form1 code:

    public partial class Form1 : Form
{

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

    #region Form_Load

    public Form1()
    {
        InitializeComponent();
    }

Here is my Program.cs code:

   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());
    }
}
}

Please, help me to fix this error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:50:15+00:00Added an answer on June 5, 2026 at 5:50 am

    I suppose you need to load one of the forms depending on the config data. If so then here is the code:

        [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);
        }
    

    Also if you need config data in one of the forms you can pass config string as constructor parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a windows application, you can create a new form and you can call
i have windows application in which i am constructing dataset with two datatables one
I am developing a windows application using c#. I am loading a file (html,
I am creating a Windows application (WPF) and C#. In my view, I have
am working in windows application with c#.Am creating the listview items dynamically..i want to
I wrote a windows application, and I have a PictureBox on my form. Now,
I've written a Windows Application to test a connection to a clients SAP web
I have a windows application running at the backend. I have functions in this
I am developing windows application which supports two language Arabic and English. I want
I have my Windows Application that accepts args and I use this in order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.