CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2007
    Posts
    5

    Small strange problem; Start windows application without a form?

    I am trying to start a Windows Application with a non form class Class1. The object of Class1 should insatiate the form Form1 like this:

    Code:
     
    namespace WindowsApplication2 
    { 
        static class Program 
        { 
            /// <summary> 
            /// The main entry point for the application. 
            /// </summary> 
            [STAThread] 
            static void Main() 
            { 
                Application.EnableVisualStyles(); 
                Application.SetCompatibleTextRenderingDefault(false); 
                Class1 someobject=new Class1(); 
                Application.Run(); 
            } 
        } 
    }

    Code:
    namespace WindowsApplication2 
    { 
        class Class1 
        { 
            private Form1 myform; 
    
            public Class1() 
            { 
                myform=new Form1(); 
            } 
        } 
    }
    Code:
    namespace WindowsApplication2 
    { 
        public partial class Form1 : Form 
        { 
            public Form1() 
            { 
                InitializeComponent(); 
            } 
        } 
    }
    The code is really simple and I can not understand why this is not working
    could anyone please give me an advice what is wrong and how to do?
    Last edited by grignard; October 19th, 2008 at 09:36 AM.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Start windows application without a form?

    You'll at least need to call Show on the form.

    Code:
    class Class1 
    { 
      private Form1 myform; 
    
      public Class1() 
      { 
        myform=new Form1();
        myform.Show( ); 
      } 
    }

  3. #3
    Join Date
    Mar 2007
    Posts
    5

    Re: Start windows application without a form?

    Ok. thank you very much for your anwer it really helped me. Why dont I have to do the show-method if I instaniate the form from the main method? I normaly create other forms from objects without using show. Is there a special need for show-method for the first form created?
    Last edited by grignard; October 19th, 2008 at 03:24 PM.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Start windows application without a form?

    The form is loaded into memory, (Form Load) then it activates (Form Activated) and then it's fianlly displayed.

    You are loading it into memory and intiializeing it, but not mapping it to the sceen namespace
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured