By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,198 Members | 925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,198 IT Pros & Developers. It's quick & easy.

VS is adding code when compiling

P: n/a
I have created a derived version of a normal form, e.g. called MyForm
(public class MyForm : System.Windows.Forms.Form). The form is simply
specifing a standard icon that we use within the company. This fairly
straight forward and not a problem. We have planed to use this form as
the base form to all other forms in our application.

The problem is the following...

When adding a button (or any other control) to the myForm the
designer/IDE(?) adds some code automatically in the
InitializeComponent method. This is also normal but in my case it add
more code than normal. Below is two pieces of code that shows my
problem. Executing the solution/project causes the form icon to change
from the company specific icon to the standard (blue/yellow/red)
icon!? If I remove the following piece of code the problem disappears,
but returns if I add a new control to the form.

this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));

This seems to a problem that is local to the solution and/or project.
I have tried to replicate the problem in other solutions without
success :( If I use a normal form (derived from
System.Windows.Forms.Form) the problem does not emerge!?

What have I done to deserve this?? How do I solve this?

Normally the InitializeComponent method looks like this...

private void InitializeComponent()
this.button1 = new System.Windows.Forms.Button();
// button1
this.button1.Location = new System.Drawing.Point(32, 56);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
// Form1
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";

In my solution it looks like this...

private void InitializeComponent()
System.Resources.ResourceManager resources = new
this.button1 = new System.Windows.Forms.Button();
// button1
this.button1.AccessibleDescription =
resources.GetString("button1.AccessibleDescription ");
this.button1.AccessibleName =
this.button1.Anchor =
((System.Windows.Forms.AnchorStyles)(resources.Get Object("button1.Anchor")));
this.button1.BackgroundImage =
((System.Drawing.Image)(resources.GetObject("butto n1.BackgroundImage")));
this.button1.Dock =
((System.Windows.Forms.DockStyle)(resources.GetObj ect("button1.Dock")));
this.button1.Enabled =
this.button1.FlatStyle =
((System.Windows.Forms.FlatStyle)(resources.GetObj ect("button1.FlatStyle")));
this.button1.Font =
((System.Drawing.Font)(resources.GetObject("button 1.Font")));
this.button1.Image =
((System.Drawing.Image)(resources.GetObject("butto n1.Image")));
this.button1.ImageAlign =
((System.Drawing.ContentAlignment)(resources.GetOb ject("button1.ImageAlign")));
this.button1.ImageIndex =
((int)(resources.GetObject("button1.ImageIndex"))) ;
this.button1.ImeMode =
((System.Windows.Forms.ImeMode)(resources.GetObjec t("button1.ImeMode")));
this.button1.Location =
((System.Drawing.Point)(resources.GetObject("butto n1.Location")));
this.button1.Name = "button1";
this.button1.RightToLeft =
((System.Windows.Forms.RightToLeft)(resources.GetO bject("button1.RightToLeft")));
this.button1.Size =
((System.Drawing.Size)(resources.GetObject("button 1.Size")));
this.button1.TabIndex =
this.button1.Text = resources.GetString("button1.Text");
this.button1.TextAlign =
((System.Drawing.ContentAlignment)(resources.GetOb ject("button1.TextAlign")));
this.button1.Visible =
// Form1
this.AccessibleDescription =
resources.GetString("$this.AccessibleDescription") ;
this.AccessibleName = resources.GetString("$this.AccessibleName");
this.AutoScaleBaseSize =
((System.Drawing.Size)(resources.GetObject("$this. AutoScaleBaseSize")));
this.AutoScroll = ((bool)(resources.GetObject("$this.AutoScroll")));
this.AutoScrollMargin =
((System.Drawing.Size)(resources.GetObject("$this. AutoScrollMargin")));
this.AutoScrollMinSize =
((System.Drawing.Size)(resources.GetObject("$this. AutoScrollMinSize")));
this.BackgroundImage =
((System.Drawing.Image)(resources.GetObject("$this .BackgroundImage")));
this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this. ClientSize")));
this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
this.Font = ((System.Drawing.Font)(resources.GetObject("$this. Font")));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObjec t("$this.ImeMode")));
this.Location = ((System.Drawing.Point)(resources.GetObject("$this .Location")));
this.MaximumSize = ((System.Drawing.Size)(resources.GetObject("$this. MaximumSize")));
this.MinimumSize = ((System.Drawing.Size)(resources.GetObject("$this. MinimumSize")));
this.Name = "Form1";
this.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetO bject("$this.RightToLeft")));
this.StartPosition =
((System.Windows.Forms.FormStartPosition)(resource s.GetObject("$this.StartPosition")));
this.Text = resources.GetString("$this.Text");

The version of Microsoft Development Environment 2003 is 7.1.3008
The version of Microsoft .NET Framework 1.1 is 1.1.4322

Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On 1 Apr 2004 05:15:07 -0800, Jonas L <jo***> wrote:
I have created a derived version of a normal form, e.g. called MyForm
(public class MyForm : System.Windows.Forms.Form). The form is simply

Check the Localizable property on the form. You probably have set it to
true, which makes all the properties be put in resources which allow you
to localize the form.

Lasse Vågsæther Karlsen
PGP KeyID: 0x0270466B
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.