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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:43:06+00:00 2026-05-14T21:43:06+00:00

I want my project to be started through an class instead of a form,

  • 0

I want my project to be started through an class instead of a form, is there any way to do this? Or to be more precise is there any good way to make sure that the first class, except Program, that is started isn’t a form-class.

I tried to change to my class in Program.main() but it looks like Application.run() needs a ApplicationContext.
I guess that I could change the Program-class to start another class and let that class start the form with Application.run() but I think that it will cause a lot of problem since I don’t want the same form to be started first each time and Application.run() have to be used at least once and at most once. So I think it will be hard to keep track of if Application.run() has been used or not.

Another question that might be even more important; Is this a good way to do things in .net? The reason I want to do so is because I want to create some sort of MVC project where the class I want to start with is the controller and all forms I’ll use will be views.

  • 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-14T21:43:06+00:00Added an answer on May 14, 2026 at 9:43 pm

    A sample implementation of a controller:

    public class Controller : ApplicationContext {
        public Controller() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            mInstance = this;
        }
        public Controller Instance { get { return mInstance; } }
        public void Start() {
            Application.Run(this);
        }
        public void Exit() {
            this.ExitThread();
        }
        public void CreateView(Form frm) {
            Views.Add(frm);
            frm.FormClosed += FormClosed;
            frm.Show();
        }
        private void FormClosed(object sender, FormClosedEventArgs e) {
            Views.Remove(sender as Form);
            // NOTE: terminate program when last view closed
            if (Views.Count == 0) Exit();
        }
        private List<Form> Views = new List<Form>();
        private Controller mInstance;
    
    }
    

    You could use it like this:

    static class Program {
        [STAThread]
        static void Main() {
            var c = new Controller();
            c.CreateView(new Form1());
            c.Start();
        }
    }
    

    Also check out the WindowsFormsApplicationBase class as a good base class for your controller. Nice support for singleton apps and splash screens.

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

Sidebar

Related Questions

I am getting started with my first MVC project and want to start off
I started my project in Asp.net MVC(c#) & SQL Server 2005.I want to implement
I've started a django project that will include an analytics app. I want that
I just started to develop my first android project. I want to add a
I started a demonstration project on HTML, JSON and jQuery recently. Thing I want
I've recently started my new private project. The main goal which I want to
in a project we want to wrap the Boost Asio socket in a way,
I've started a CI project and I'm going to use it with Doctrine, there
So today I started learning ASP.NET. Unfortunately I haven't found any good tutorials online,
I just started with solving Project Eulers problems. Even though this one is very

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.