I'm using Visual Studio 2013 to create a Visual C# Windows Forms Application and I'm not using the Designer to setup the form.
I have what I think is a simple timer that should pause my application for a few seconds to allow a splash screen to be shown before the user can see and access the menu. But when I run debug the application doesn't appear on the screen until the timer is done and then it has jumped past the splash screen. I've looked at different ways to do timers and tried to search for help on this for hours now but cannot find a way to make it work. I'm guessing that I'm missing something very obvious but as a newbie I can't spot it.
Any help would be greatly appreciated.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Timers;
namespace SimpleForm
{
public class TheForm : Form
{
private MenuStrip menuStrip;
private MainMenu menuMain;
private MenuItem menuBlockFile;
private MenuItem menuBlockOthers;
private MenuItem menuItemExit;
private MenuItem menuItemHints;
static Bitmap imgIntroBg = null;
static Bitmap imgMenuBg = null;
private Panel pnlIntro;
private Panel pnlMenu;
static int counter = 1;
static System.Timers.Timer timer;
public TheForm()
{
FormInitialize();
MenuInitialize();
introDisplay();
MenuDisplay(true);
}
private void FormInitialize()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Game));
this.SuspendLayout();
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(714, 462);
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.Name = "SimpleForm";
this.Text = "Simple Form";
ControlBox = false;
BackColor = System.Drawing.Color.Black;
StartPosition = FormStartPosition.CenterScreen;
this.ResumeLayout(false);
}
private void MenuInitialize()
{
this.SuspendLayout();
this.menuStrip = new MenuStrip();
this.menuMain = new MainMenu();
this.menuBlockFile = new MenuItem();
this.menuBlockOthers = new MenuItem();
this.menuItemExit = new MenuItem();
this.menuItemHints = new MenuItem();
this.menuMain.MenuItems.AddRange(new MenuItem[] {
this.menuBlockFile,
this.menuBlockOthers});
this.menuBlockFile.Index = 0;
this.menuBlockFile.MenuItems.AddRange(new MenuItem[] {
this.menuItemExit
} );
this.menuBlockFile.Text = "File";
this.menuBlockOthers.Index = 1;
this.menuBlockOthers.MenuItems.AddRange(new MenuItem[] {
this.menuItemHints
});
this.menuBlockOthers.Text = "Others";
this.menuItemExit.Index = 0;
this.menuItemExit.Text = "Exit";
this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
this.menuItemHints.Checked = true;
this.menuItemHints.Index = 0;
this.menuItemHints.Text = "Temp";
this.menuItemHints.Click += new System.EventHandler(this.menuItemExit_Click);
this.Menu = this.menuMain;
imgMenuBg = new Bitmap("graphics/layout/menubg.png");
pnlMenu = new Panel();
pnlMenu.Name = "pnlMenu";
pnlMenu.Location = new Point(0, 0);
pnlMenu.Width = 714;
pnlMenu.Height = 462;
pnlMenu.BackgroundImage = imgMenuBg;
MenuDisplay(false);
this.ResumeLayout(false);
}
private void MenuDisplay(bool display)
{
this.menuBlockFile.Visible = display;
this.menuBlockOthers.Visible = display;
if (display == true) {
Controls.Add(pnlMenu);
} else {
Controls.Remove(pnlMenu);
}
}
private void introDisplay()
{
timer = new System.Timers.Timer();
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Interval = 5*1000;
timer.Enabled = true;
imgIntroBg = new Bitmap("graphics/layout/Introbg.png");
pnlIntro = new Panel();
pnlIntro.Name = "pnlIntro";
pnlIntro.Location = new Point(0, 0);
pnlIntro.Width = 714;
pnlIntro.Height = 482;
pnlIntro.BackgroundImage = imgIntroBg;
timer.Start();
Controls.Add(pnlIntro);
while (counter != 0)
{
}
Controls.Remove(pnlIntro);
}
private static void timer_Elapsed(object source, ElapsedEventArgs e)
{
counter = 0;
timer.Stop();
}
private void menuItemExit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}