RE: Show/Hide Forms
- From: "Charcoal" <Charcoal@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Dec 2005 09:36:04 -0800
Ok..maybe I can make this easier to understand….
Why doesn’t this work in the form_Load event? (I am using Visual Studio
2005, compact framework 2.0 and testing on a Dell Axim using Mobile 5.0 OS)
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[MTAThread]
static void Main()
{
Application.Run(new frmSplash());
}
}
private void Splash_Load(object sender, EventArgs e)
{
this.Show();
this.Refresh();
frmLogin Login = new frmLogin();
Login.Show();
Login.Refresh();
this.Hide();
}
Every time I try, the frmSplash (AKA this) is shown, frmLogin (AKA Login) is
created, frmLogin is shown, frmSplash hides, at the end of the load method
frmSplash is made visible and is the topmost form!!!!!!!
Please, for the love of God and all that is holy...please help. Thanks
--
Charcoal
Going Mobile...Keep me moving.
"Charcoal" wrote:
> K...this is making me crazy! First, I only have two forms...
>
> The Splash screen is the main()
>
> I used to do this:
>
> static void Main()
> {
> Application.Run(new frmSplashScreen());
> }
>
> ....Initialize Code...
>
> private void frmSplashScreen_Load(object sender, EventArgs e)
> {
> this.Update();
> this.Show();
> frmCommunities mainForm = new frmCommunities();
> this.Hide();
> mainForm.Show();
> }
>
> This was no problem and worked fine.
>
> Now I am working in Visual Studio 2005 and this doesn't work. What the HE!!
>
> Some noteable differences. VS '05 creates a program.cs which is the Main()
>
> static class Program
> {
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
>
> [MTAThread]
> static void Main()
> {
> Application.Run(new frmSplash());
> }
>
> }
>
>
> ...then there is the Designer.cs that is a partial class and contains the
> InitializeComponent code...
>
> I placed my code in the partial class and here it is....
>
> using System;
> using System.Collections.Generic;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Text;
> using System.Windows.Forms;
> using System.Data.SqlServerCe;
> using System.Reflection;
> using System.IO;
>
> namespace eScheduleMobile
> {
> public partial class frmSplash : Form
> {
> #region variables
> private DataManager DM;
> private frmLogin Login;
> #endregion
>
> public frmSplash()
> {
> InitializeComponent();
> }
>
> private void Splash_Load(object sender, EventArgs e)
> {
> this.Show();
> this.Refresh();
>
> if (!ConfigApp())
> {
> Application.Exit();
> }
>
> Login.Show();
> Login.Refresh();
> this.Hide();
> }
>
> private bool ConfigApp()
> {
> bool AppReady = false;
> DM = new DataManager();
>
> try
> {
> if (!initDB())
> {
> this.lblMessage.Text = "Failed to create data file.
> Application will exit.";
> this.lblMessage.Refresh();
> AppReady = false;
> }
> else
> {
> this.lblMessage.Text = "Data file was updated.";
> this.lblMessage.Refresh();
> AppReady = true;
> }
> if (!initLogin())
> {
> this.lblMessage.Text = "Login form could not be created.";
> this.lblMessage.Refresh();
> AppReady = false;
> }
> else
> {
> this.lblMessage.Text = "Configuration complete.";
> this.lblMessage.Refresh();
> AppReady = true;
> }
> }
> catch
> {
>
> }
>
> return AppReady;
> }
>
> private bool initDB()
> {
> try
> {
> //Check to see if data file (sdf) was created.
> //If not, 'CheckDB will create one.
> if (DM.CheckDB(false))
> {
> //Now we add Tables and Indices using the
> 'eScheduleMobile.DB.xml' config file
> if (!DM.CreateDatabase())
> {
> this.lblMessage.Text = "Data Failure. Failed to
> create tables.";
> this.lblMessage.Refresh();
> return false;
> }
> if (!DM.CreateIndices())
> {
> this.lblMessage.Text = "Data Failure. Failed to
> create indices.";
> this.lblMessage.Refresh();
> return false;
> }
>
> this.lblMessage.Text = "Data file created.";
> this.lblMessage.Refresh();
> }
> }
> catch
> {
>
> }
>
> //Return true if DB was created or already exists.
> return true;
> }
>
> private bool initLogin()
> {
> Login = new frmLogin();
> return true;
> }
>
> private void btnContinue_Click(object sender, EventArgs e)
> {
> Login.Show();
> Login.Refresh();
> this.Hide();
> }
> }
> }
>
>
>
> ....K, The Splash page shows and displays updates as data is created and the
> login form is created. The login form should be displayed and the Splash page
> hidden. It works right up until the Load event ends. Then the hidden Splash
> page is AGAIN displayed, even after I told it to Hide.
>
> Side note: WORKS GREAT IF I CLICK THE BUTTON. Just not in the load even
> ....WHY, why oh why....
> --
> Charcoal
> Going Mobile...Keep me moving.
.
- Follow-Ups:
- Re: Show/Hide Forms
- From: Chris Tacke, eMVP
- Re: Show/Hide Forms
- References:
- Show/Hide Forms
- From: Charcoal
- Show/Hide Forms
- Prev by Date: Re: Connect to SQL2K5
- Next by Date: Mobile 5.0 deploy multiple CAB - wce-load.exe
- Previous by thread: Show/Hide Forms
- Next by thread: Re: Show/Hide Forms
- Index(es):