Jim Fell
Jim Fell

Reputation: 14254

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

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?

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.

Upvotes: 13

Views: 44894

Answers (6)

user2176206
user2176206

Reputation: 1

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

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

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 Code button <>.

Upvotes: 0

Licerio
Licerio

Reputation: 1

I faced same problem before but I solved it by removing the statements below the 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();
    }
}

Upvotes: 0

user172632
user172632

Reputation:

Got it.

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

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

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

Upvotes: 17

McAden
McAden

Reputation: 13970

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

Upvotes: 0

Frederik Gheysels
Frederik Gheysels

Reputation: 56964

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

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.

Upvotes: 3

Marc Gravell
Marc Gravell

Reputation: 1063864

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?

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

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

Upvotes: 10

Related Questions