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 8072369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:59:47+00:00 2026-06-05T13:59:47+00:00

I run LoginForm using the code below: [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);

  • 0

I run LoginForm using the code below:

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new LoginForm());
    //Application.Run(new MainForm());
}

When user presses the enter button, i want to dispose or close the LoginForm and want to run the MainForm but i got this exception: “InvalidOperationException was unhandled by user code”

Click handler of the enter button is given below:

private void LoginFormEnterButton_Click(object sender, EventArgs e)
{
    try
    {
        MainForm a = new MainForm();
        a.Show();
        this.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

What can i do to dispose the LoginForm and after that to run the MainForm successfully?

  • 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-05T13:59:48+00:00Added an answer on June 5, 2026 at 1:59 pm

    You can’t dispose the Main window. You need to change the way.

    First of all set MainForm as startup window.

    Application.Run(new MainForm());
    

    Load/show the LoginForm in constructor of MainForm,

    public MainForm()
    {
     LoginForm login=new LoginForm();
     login.ShowDialog();
     InitializeComponent();
    }
    

    and Click handler code in LoginForm,

    private void LoginFormEnterButton_Click(object sender, EventArgs e)
    {
       this.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my main method, I start the main form as usual: Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new
I have application with this code: Module Startup <STAThread()> _ Public Sub Main() Try
I have this code: using ( var site = new SPSite( myUrl ) )
We run an AI programming competition in which contestants will code an AI that
I run a simple SELECT (noted below) in a stored procedure of a table
I'm creating login form using JSF 2.0. Below is the detailed description. When I
I have 3 classes: Form1, LoginForm and program. Program holds my main method that
Run the following code In Mathematica: r=6197/3122; p[k_,w_]:=Sqrt[w^2/r^2-k^2];q[k_,w_]:=Sqrt[w^2-k^2]; a[k_,w_,p_,q_]:=(k^2-q^2)^2 Sin[p]Cos[q]+4k^2 p q Cos[p]Sin[q] a[k_,w_]:=a[k,w,p[k,w],q[k,w]];
Hai i have a application using background service.its running clearly.If my mobile is switch
I'm trying to figure out why my form validation run function is returning false.

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.