如何让关于框出现在 C# 中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1977475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:20:59  来源:igfitidea点击:

How do I get the About box to appear in C#?

c#about-box

提问by Jim Fell

I have an About box in my C# project using Microsoft's Visual C# 2008 Express Edition named AboutBox1. I have made it look how I want it in the design view, but how do I make it appear when the About link in the Help menu is clicked?

我的 C# 项目中有一个 About 框,使用 Microsoft 的 Visual C# 2008 Express Edition,名为 AboutBox1。我已经让它在设计视图中看起来像我想要的那样,但是当单击“帮助”菜单中的“关于”链接时如何让它出现?

This codes makes an About box appear, but it looks blank. It's not the one I designed.

此代码使一个关于框出现,但它看起来是空白的。这不是我设计的。

  private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  {
     AboutBox1 box = new AboutBox1();
     box.ShowDialog();
  }

Any thoughts or suggestions would be appreciated. Thanks.

任何想法或建议将不胜感激。谢谢。

采纳答案by McAden

Got it.

知道了。

The about box is driven off of assembly properties for your project.

关于框是从您的项目的装配属性驱动的。

Go to Project -> 'ProjectName' Properties -> Assembly Information.

转到项目 -> 'ProjectName' 属性 -> 程序集信息。

You set all of the information there.

您在那里设置所有信息。

If you try to set the information in the Property Explorer it will simply be over written at run time by what ever is in this window.

如果您尝试在属性资源管理器中设置信息,它将在运行时被此窗口中的任何内容覆盖。

Cheers, Mike

干杯,迈克

回答by Marc Gravell

It sounds to me like a borked designer surface... have you hit save and rebuilt it? Perhaps close the IDE, reopen it, and check that your carefully designed form is still pretty?

在我看来,这听起来像是一个无聊的设计师表面……你有没有点击保存并重建它?也许关闭 IDE,重新打开它,然后检查您精心设计的表单是否仍然漂亮?

BTW, when using ShowDialogyou should also use using(since it doesn't Dispose()itself when shown with ShowDialog):

顺便说一句,使用时ShowDialog你也应该使用using(因为它本身不是Dispose()用 显示时ShowDialog):

using(AboutBox1 box = new AboutBox1()) {
    box.ShowDialog(this);
}

回答by Frederik Gheysels

Did you remove the method-call to 'InitializeComponent' in the constructor of your AboutBox - form ?

您是否在 AboutBox 表单的构造函数中删除了对“InitializeComponent”的方法调用?

Your constructor should at least look like this:

你的构造函数至少应该是这样的:

    public partial class AboutBox : Form
    {
        public AboutBox()
        {
            InitializeComponent ();
        }
    }

Where the InitializeComponent method call should be the first line in the constructor.

InitializeComponent 方法调用应该是构造函数中的第一行。

回答by McAden

If it appears but is blank, the problem is in AboutBox1. Show us some of that code.

如果出现但为空白,则问题出在 AboutBox1 中。向我们展示一些代码。

回答by Licerio

I faced same problem before but I solved it by removing the statements below the InitializeComponent();

我以前遇到过同样的问题,但我通过删除下面的语句来解决它 InitializeComponent();

Default code:

默认代码:

partial class AboutBox1 : Form
{
    public AboutBox1()
    {
        InitializeComponent();
        this.Text = String.Format("About {0} {0}", AssemblyTitle);
        this.labelProductName.Text = AssemblyProduct;
        this.labelVersion.Text = String.Format("Version {0} {0}", AssemblyVersion);
        this.labelCopyright.Text = AssemblyCopyright;
        this.labelCompanyName.Text = AssemblyCompany;
        this.textBoxDescription.Text = AssemblyDescription;
    }
}

My final code:

我的最终代码:

partial class AboutBox1 : Form
{
    public AboutBox1()
    {
        InitializeComponent();
    }
}

回答by user2176206

I couldn't find the project / project name/ assembly properties.

我找不到项目/项目名称/程序集属性。

But commenting out the lines after InitializeComponent();worked for me.

但是InitializeComponent();在为我工作后注释掉这些台词 。

This is how mine looks:

这是我的样子:

 public frmAboutBox1()
    {
        InitializeComponent();
        //this.Text = String.Format("About {0}", AssemblyTitle);
        //this.labelMyFFEProductName.Text = AssemblyProduct;
        //this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion);
        //this.labelCopyright.Text = AssemblyCopyright;
        //this.labelCompanyName.Text = AssemblyCompany;
        //this.textBoxDescription.Text = AssemblyDescription;
    }

If you are an amateur like me, to find these lines, click the AboutBox in the project explorer, and hit the View Codebutton <>.

如果您是像我这样的业余爱好者,要找到这些行,请单击项目资源管理器中的 AboutBox,然后单击View Code按钮<>