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

  • Home
  • SEARCH
  • 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 6947279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:40:25+00:00 2026-05-27T13:40:25+00:00

In .NET (language: C#) when writing Windows Applications we start the application with a

  • 0

In .NET (language: C#) when writing Windows Applications we start the application with a form passed to Application.Run.

But when you have an Application where you don’t have a single window to keep it alive…
But rather if any of one type of forms is active you wan’t the application to remain.

What I have is e.g. a Login Screen that when the user successfully log’s in, I wan’t to close.
However calling “Close()” obviously closes the entire app since the login screen is the one passed to the Application.Run.

The next screen has the same “fate” so can’t use that either, that will be a screen where the user selects something and then it closes.

Anyways… long story short. I have a few ideas, but all involving some not so neat things.
So what I am asking for here is sort of a “Best Practice” in these cases.
This is not something with a definitive awnser, I know that, so please all good ideas are welcome and discussions around them.

  • 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-05-27T13:40:26+00:00Added an answer on May 27, 2026 at 1:40 pm

    The Code Project article ended up being the basis for the solution (as it is now).

    There is still some parts to sort out in the “Navigator” part, but the override of the context works perfectly.

    The essence of the implementation:

    public class ApplicationContextNavigator : ApplicationContext, INavigator
    {
      private readonly IWindsorContainer container;
      private IView Current { ... }
      public ApplicationContextNavigator(IWindsorContainer container) {...}
      public void Start<TView>() where TView : IView { ... }
      public void Start<TView>(IViewInitializer initializer) where TView : IView
      {
        Current = InitializeView<TView>(initializer);
        Application.Run(this);
      }
    
      public void Navigate<TView>() where TView : IView { ... }
      public void Navigate<TView>(IViewInitializer initializer) where TView : IView
      {
        IView closing = Current;
        IView showing = InitializeView<TView>(initializer);
    
        showing.Location = closing.Location;
        showing.Show();
    
        Current = showing;
        closing.Close();
      }
    
      private IView InitializeView<TView>(IViewInitializer initializer) where TView : IView
      {
        IView view = container.Resolve<TView>();
        initializer.Initialize(view);
        return view;
      }
    
      protected override void OnMainFormClosed(object sender, EventArgs e)
      {
        if(sender == Current)
        {
          base.OnMainFormClosed(sender, e);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am done with .NET and web dev. and want to start writing applications
I am using vb.net language I have a dropdownlist, which is filled by below
I'm working on writing a compiler for a language running on .net and one
I have the following VB.NET code (but for each loops are in most languages,
We have a mature Windows desktop application written in C++. The application's GUI sits
I am writing an MFC application that doesn't use .NET (CLR support is set
I'm about to start writing a tool in .NET 2.0 (C#), and the tool
I have started writing an application that gets in a certain website and gets
I'm planning on writing a medium-size WinForms application that I'll write in C#, .NET
I'm developing a web app in asp.net mvc using jquery, the language of application

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.