我在C#中有多个表单,当我调试时,不再显示

时间:2011-11-24 00:28:35

标签: c# winforms

我对C#很新,但是当我尝试调试我的程序时,没有显示任何内容。我有多种形式,第一种只是一个菜单,所以我可以转到其他形式。

这是我的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);

        }
    }
}

这是同一形式的设计师:

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;
    }
}

请帮助:(

1 个答案:

答案 0 :(得分:3)

首先,你必须有一个program.cs或类似的东西,它定义了静态void Main()。

在这个program.cs中,你应该有类似于这个的代码来启动应用程序并显示初始形式:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new frmMainMenu());
    }
}

最后,在项目的属性中,选择Application区域并确保在Startup object下拉列表中选择了您的Program类。

如果所有这些都存在,那么您在某个地方遇到了需要使用try/catch语句进行追踪的异常。