Hard coded Tool button image being remove by IDE automatically

K

Kevin.Li

Hi all,

Any criticism will be appreciated.

I have a project coded in VS.NET 2003, and I am moving to VS.NET 2005
and convert to Project to VS.NET 2005 Version. In the former project,
I have an object: POImageList which is type of
System.Windows.Forms.ImageList and holds 6 Images.

I add the following codes to InitializeComponent() part:

//
toolStripButton1.image = POImageList,Images[0];

Then I build and run the project, It works well and the result is
exactly what I want.

However, The Problem is:

When I return to the designer mode and build the project again, the
IDE remove the line: toolStripButton1.image = POImageList,Images[0];
When I run the project, Nothing appears on toolStripButton1. I tried
serveral times, but things are the same.

Does anyone else has this kind of problems?

Thanks again.
 
G

Guest

Hi Kevin.Li

You shouldn't put any code in the InitializeComponent() method, as Visual
Studio can (and does) regenerate the method when you modify the form.
You should put your assignment in the constructor for your form, just after
the InitializeComponent() method is called. e.g.

public partial class UI : System.Windows.Forms.Form
{
public UI()
{
InitializeComponent();

toolStripButton1.image = POImageList,Images[0];
}

...
}

Making the assignment after the call to InitalizeComponent() ensures the
toolsStripButton1 object has been initialized.
And, Visual Studio will never overwrite the code in your own constructor.

Hope that helps
 
K

Kevin.Li

Hi Kevin.Li

You shouldn't put any code in the InitializeComponent() method, as Visual
Studio can (and does) regenerate the method when you modify the form.
You should put your assignment in the constructor for your form, just after
the InitializeComponent() method is called. e.g.

public partial class UI : System.Windows.Forms.Form
{
public UI()
{
InitializeComponent();

toolStripButton1.image = POImageList,Images[0];
}

...

}

Making the assignment after the call to InitalizeComponent() ensures the
toolsStripButton1 object has been initialized.
And, Visual Studio will never overwrite the code in your own constructor.

Hope that helps

--
Ged Morettawww.appsense.com

-----------------------------------------------------------------------
This signature isn't automatic. I have to type it manually every time.




Any criticism will be appreciated.
I have a project coded in VS.NET 2003, and I am moving to VS.NET 2005
and convert to Project to VS.NET 2005 Version. In the former project,
I have an object: POImageList which is type of
System.Windows.Forms.ImageList and holds 6 Images.
I add the following codes to InitializeComponent() part:
//
toolStripButton1.image = POImageList,Images[0];
Then I build and run the project, It works well and the result is
exactly what I want.
However, The Problem is:
When I return to the designer mode and build the project again, the
IDE remove the line: toolStripButton1.image = POImageList,Images[0];
When I run the project, Nothing appears on toolStripButton1. I tried
serveral times, but things are the same.
Does anyone else has this kind of problems?
Thanks again.- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -

Yeah!
Thanks a zillion.
Since I am a new hand in DotNet, I am confused with this problem for
the whole evening. OK, It's late in China now. I am going to bed. Your
answer will help me to enjoy a more comfortable sleep.

Thanks again.
 
K

Kevin.Li

Hi Kevin.Li

You shouldn't put any code in the InitializeComponent() method, as Visual
Studio can (and does) regenerate the method when you modify the form.
You should put your assignment in the constructor for your form, just after
the InitializeComponent() method is called. e.g.

public partial class UI : System.Windows.Forms.Form
{
public UI()
{
InitializeComponent();

toolStripButton1.image = POImageList,Images[0];
}

...

}

Making the assignment after the call to InitalizeComponent() ensures the
toolsStripButton1 object has been initialized.
And, Visual Studio will never overwrite the code in your own constructor.

Hope that helps

--
Ged Morettawww.appsense.com

-----------------------------------------------------------------------
This signature isn't automatic. I have to type it manually every time.




Any criticism will be appreciated.
I have a project coded in VS.NET 2003, and I am moving to VS.NET 2005
and convert to Project to VS.NET 2005 Version. In the former project,
I have an object: POImageList which is type of
System.Windows.Forms.ImageList and holds 6 Images.
I add the following codes to InitializeComponent() part:
//
toolStripButton1.image = POImageList,Images[0];
Then I build and run the project, It works well and the result is
exactly what I want.
However, The Problem is:
When I return to the designer mode and build the project again, the
IDE remove the line: toolStripButton1.image = POImageList,Images[0];
When I run the project, Nothing appears on toolStripButton1. I tried
serveral times, but things are the same.
Does anyone else has this kind of problems?
Thanks again.- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -

Thanks a zillion.
I was confused for this question for a whole evening and your anwser
helped out.
you look like a million dollars!
Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top