RJ Lohan
RJ Lohan

Reputation: 6527

Icon not shown at runtime in derived Windows form

I have a C# app where one of my Form icons is visible in the designer but reverts to the default icon at runtime. The form in question is a derived form, with no .designer.cs file of its own, and the derived form .cs file is empty. The form icon displays in the designer correctly, but at runtime the icon is missing.

The derived form is in a different project from the base form. The base form icon was added via the designer, and no modifications were made to the base .designer.cs file.

Any ideas what might be causing this?

Upvotes: 1

Views: 1553

Answers (1)

RJ Lohan
RJ Lohan

Reputation: 6527

After mucking about for a bit, I think my problem is related to this bug in VS: https://connect.microsoft.com/VisualStudio/feedback/details/106264/mdi-form-icon-formborderstyle-windowstate-maximized#tabs

I got around my issue by re-adding the Icon to the derived form (using the designer), and then also had to add a _Load handler with the following

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MyForm));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

Does the job, though I don't enjoy hacky workarounds!

Upvotes: 1

Related Questions