I’m fairly new to C#, however when I try to debug my program nothing is shown. I have multiple forms and the first one is just a menu so I could go to the other forms.
This is my Form1.cs:
namespace EscapeLabryinth
{
public partial class frmMainMenu : Form
{
frmGameMenu secondForm = new frmGameMenu();
frmHowToPlay thirdForm = new frmHowToPlay();
Music bgMusic;
public frmMainMenu()
{
InitializeComponent();
}
private void btnPlay_Click(object sender, EventArgs e)
{
secondForm.Show();
this.Hide();
}
private void btnInstru_Click(object sender, EventArgs e)
{
thirdForm.Show();
this.Hide();
}
private void btnQuit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnAudio_Click(object sender, EventArgs e)
{
}
private void frmMainMenu_Load(object sender, EventArgs e)
{
//Create a new Music object to play the background music
bgMusic = new Music(Application.StartupPath + @"\resources\music\eurekaost.wav", true);
bgMusic.LoopPlay();
bgMusic.SetVolume(-100);
}
}
}
This is the same form’s designer:
namespace EscapeLabryinth
{
partial class frmMainMenu
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMainMenu));
this.btnQuit = new System.Windows.Forms.Button();
this.lblTitleMenu = new System.Windows.Forms.Label();
this.btnAudio = new System.Windows.Forms.Button();
this.btnInstru = new System.Windows.Forms.Button();
this.btnPlay = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnQuit
//
this.btnQuit.BackColor = System.Drawing.Color.Firebrick;
this.btnQuit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnQuit.Font = new System.Drawing.Font("Hand Me Down S BRK", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnQuit.Location = new System.Drawing.Point(250, 290);
this.btnQuit.Name = "btnQuit";
this.btnQuit.Size = new System.Drawing.Size(150, 39);
this.btnQuit.TabIndex = 2;
this.btnQuit.Text = "Quit";
this.btnQuit.UseVisualStyleBackColor = false;
this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click);
//
// lblTitleMenu
//
this.lblTitleMenu.AutoSize = true;
this.lblTitleMenu.BackColor = System.Drawing.Color.Black;
this.lblTitleMenu.Font = new System.Drawing.Font("Vindictive BRK", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblTitleMenu.ForeColor = System.Drawing.Color.White;
this.lblTitleMenu.Location = new System.Drawing.Point(83, 18);
this.lblTitleMenu.Name = "lblTitleMenu";
this.lblTitleMenu.Size = new System.Drawing.Size(532, 28);
this.lblTitleMenu.TabIndex = 3;
this.lblTitleMenu.Text = "Venture The Great Labryinth";
//
// btnAudio
//
this.btnAudio.BackgroundImage = global::EscapeLabryinth.Properties.Resources.speakers;
this.btnAudio.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.btnAudio.Location = new System.Drawing.Point(632, 355);
this.btnAudio.Name = "btnAudio";
this.btnAudio.Size = new System.Drawing.Size(54, 73);
this.btnAudio.TabIndex = 4;
this.btnAudio.UseVisualStyleBackColor = true;
this.btnAudio.Click += new System.EventHandler(this.btnAudio_Click);
//
// btnInstru
//
this.btnInstru.BackColor = System.Drawing.Color.DarkSlateGray;
this.btnInstru.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnInstru.Font = new System.Drawing.Font("Hand Me Down S BRK", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnInstru.Location = new System.Drawing.Point(253, 190);
this.btnInstru.Name = "btnInstru";
this.btnInstru.Size = new System.Drawing.Size(150, 39);
this.btnInstru.TabIndex = 5;
this.btnInstru.Text = "How To Play";
this.btnInstru.UseVisualStyleBackColor = false;
this.btnInstru.Click += new System.EventHandler(this.btnInstru_Click);
//
// btnPlay
//
this.btnPlay.BackColor = System.Drawing.Color.Gold;
this.btnPlay.FlatAppearance.BorderSize = 0;
this.btnPlay.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnPlay.Font = new System.Drawing.Font("Hand Me Down S BRK", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnPlay.ForeColor = System.Drawing.Color.Black;
this.btnPlay.Location = new System.Drawing.Point(250, 92);
this.btnPlay.Name = "btnPlay";
this.btnPlay.Size = new System.Drawing.Size(150, 39);
this.btnPlay.TabIndex = 6;
this.btnPlay.Text = "Venture!";
this.btnPlay.UseVisualStyleBackColor = false;
this.btnPlay.Click += new System.EventHandler(this.btnPlay_Click);
//
// frmMainMenu
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = global::EscapeLabryinth.Properties.Resources.labyrinth;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ClientSize = new System.Drawing.Size(687, 437);
this.Controls.Add(this.btnPlay);
this.Controls.Add(this.btnInstru);
this.Controls.Add(this.btnAudio);
this.Controls.Add(this.lblTitleMenu);
this.Controls.Add(this.btnQuit);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "frmMainMenu";
this.Text = "Main Menu";
this.Load += new System.EventHandler(this.frmMainMenu_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnQuit;
private System.Windows.Forms.Label lblTitleMenu;
private System.Windows.Forms.Button btnAudio;
private System.Windows.Forms.Button btnInstru;
private System.Windows.Forms.Button btnPlay;
}
}
Please help 🙁
First, you must have a program.cs or something similar that has a static void Main() defined.
In this program.cs, you should have code that looks similar to this to get the application started and show the initial form:
And finally, in your Project’s Properties, select the
Applicationarea and ensure that your Program class is selected in theStartup objectdropdown.If all this is in place, then you are encountering an exception somewhere that you need to track down with a
try/catchstatement.