无法在C#中显示新表单(aboutBox)

时间:2011-10-08 19:51:43

标签: c#

IDE /语言:Visual Studio 2010 Professional C#

我正撞在墙上撞墙。我的应用程序差不多完成但我遇到了一个愚蠢的问题。单击“我的关于框”菜单项时,无法启动我的关于框。它既不显示任何内容,也不会创建新表单。

我已经在下面的Stack Overflow上尝试了几个建议,但是没有一个建议启动我的aboutBox类。 (注意:我单独尝试了这些,而不是一次性尝试):

来自mainWindow.cs的

片段:

 private void aboutMyProjectToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Application.Run(new aboutBox()); //throws and exception

        (new aboutBox()).ShowDialog(); //creates a new form does not run the one I created

        aboutBox about = new aboutBox(); 
        about.ShowDialog(); //creates a new form does not run the one I created
    }

这是aboutBox.cs中的内容:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace myNamespace
{
    public partial class aboutBox : Form
    {
        public void aboutBoxMain()
        {
            InitializeComponent();
            this.Text = String.Format("About {0}", AssemblyTitle);
            this.labelProductName.Text = AssemblyProduct;
            this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion);
            this.labelCopyright.Text = AssemblyCopyright;
            this.textBoxDescription.Text = AssemblyDescription;
        }
    #region "Assembly Accessors"
    ...
    #endregion
    #region "On-click Events"
    ...
    #endregion
    }
}

先谢谢你了!

1 个答案:

答案 0 :(得分:3)

    public void aboutBoxMain()
    {
        InitializeComponent();
        // etc..
    }

你以某种方式破坏了构造函数,可能是在重命名表单并试图摆脱编译器错误之后。修正:

    public aboutBox() 
    {
        InitializeComponent();
        // etc..
    }