Results 1 to 9 of 9

Thread: Splash screen

Threaded View

  1. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Posts
    185

    Re: Splash screen

    To get Form1 (main form) to close Form2 (splash screen, but also "host" form or "main" form or whatever you call the form that the program starts), I followed some code from another link regarding storing an instance variable.

    I made a property inside of Form1 called InstanceRef:

    C# Code:
    1. private Form m_InstanceRef = null;
    2. public Form InstanceRef
    3. {
    4.   get { return m_InstanceRef;}
    5.   set { m_InstanceRef = value;}
    6. }

    Then, where Form2 opens Form1, I changed it to look like this:

    C# Code:
    1. Form1 mainform = new Form1();
    2. mainform.InstanceRef = this;
    3. mainform.Show();
    4. this.Hide();

    Then, in Form1.FormClosed event, I did:

    C# Code:
    1. //Shutdown all timers
    2. tim1.Enabled = false;
    3. tim2.Enabled = false;
    4.  
    5. //Close forms
    6. this.InstanceRef.Dispose();
    7. this.Dispose();

    This closes the whole app, and seems to work OK.

    Two questions, though, first, after I dispose the "main" form, should I do a this.Dispose() like I did? Since the first .Dispose() is closing the main form, I think it is thereby closing the form that the this.Dipose() is trying to dispose? Will/can this cause an error to do this, or is an OK "backup plan?"

    The second question is, overall, is the the "right" way to do this, and if not, is there a better/simpler/easier/preferred way to do it?

    (edited for a code mistype)
    Last edited by pjrage; Apr 25th, 2007 at 01:26 PM.

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