locked
CF35: Setting the initial form at run-time RRS feed

  • Question

  • I'm developing an .NET CF35 application that is to show either of two forms at startup, depending on wether or not the app is configured by the user. This has proven to be quite a headache for me. Program.cs launches one single form as the "master form" in the Application.Run()-call. When that master form closes, the application terminates. Due to this fact, I found it troublesome to have a dynamic master form (Approach A), because then the forms themsevles had to make sure they didn't close before all other forms were closed, or else the application would terminate. The solution I've tried to implement is based on another approach (B):

    Here a single, constant master form always initiates from Program.cs, performing Form_Load and then spawns the child form if the settings file is ok, finally calling Hide() on itself. The user will not see the initial form. But then another problem rises: Although the initial form is never shown, its MENU hangs at the bottom of the screen (MainMenu) even after the child form is shown. As soon as the user touches the screen, the menu is replaced by the menu of the child form though (but this is not good enough). I've done some debugging and have discovered that the initial form recieves several Activated events after the child form is created and initialized, and after the inital Form_Load and Form_Activated is called on the inital form.

    -Do anyone have any idea on why the first form receives many (I count 4) activated-events AFTER Hide() is called? There are no calls to the master form from the child form.
    -Is my approach sound? Are there better ways to acheive  what I want?
    -Do anyone have a good source where I can read up on the event model for forms in the Compact Framework, as it seems to differ some from the Windows Forms?

    Help appreciated
    Tuesday, January 5, 2010 11:08 PM

Answers

  • Why not modify the Program.cs to select which form to load?
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    • Marked as answer by ZHE ZHAO Tuesday, January 12, 2010 5:14 AM
    Wednesday, January 6, 2010 3:22 AM
  • Hi,

     

    You may consider calling showdialog() instead of show() if you want to close the new form every time.

    Or,

    I tried to create a new form under GotFocus Eventhandler of Form1, it seems to work for me.

      private void Form1_GotFocus(object sender, EventArgs e)

            {

                Form2 f2 = new Form2 ();

                f2.Show();

            }

     

    Hope this helps,

    Zhe Zhao

     

    • Marked as answer by ZHE ZHAO Tuesday, January 12, 2010 5:14 AM
    Friday, January 8, 2010 7:51 AM

All replies

  • Why not modify the Program.cs to select which form to load?
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    • Marked as answer by ZHE ZHAO Tuesday, January 12, 2010 5:14 AM
    Wednesday, January 6, 2010 3:22 AM
  • That's what I tried to explain with Approach A. I got problems because I used Close() and not Hide() when swapping between the two forms, as the application terminated at unwanted times. But I'll try the approach once more now as I have redesigned to use Hide() and keep references to the windows at all times. I'll post the results when I'm done.

    I'd still be interested in documentation on the Compact Framework Forms event model though.. I'm still puzzeled over all the Activated calls after Load.
    Wednesday, January 6, 2010 12:26 PM
  • Hi,

     

    You may consider calling showdialog() instead of show() if you want to close the new form every time.

    Or,

    I tried to create a new form under GotFocus Eventhandler of Form1, it seems to work for me.

      private void Form1_GotFocus(object sender, EventArgs e)

            {

                Form2 f2 = new Form2 ();

                f2.Show();

            }

     

    Hope this helps,

    Zhe Zhao

     

    • Marked as answer by ZHE ZHAO Tuesday, January 12, 2010 5:14 AM
    Friday, January 8, 2010 7:51 AM
  • Yes ShowDialog might be solution also. I ended up coding a bit of login in Program.cs - performing a conditional Application.Run in a loop. It works, so now I won't be touching anything :)
    Tuesday, January 12, 2010 2:55 PM