Click here to Skip to main content
15,922,166 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have this code :
VB
this.toolStripCategories.Location = new Point(3, 138);
            this.toolStripCategories.Name = "toolStripCategories";
            this.toolStripCategories.Size = new Size(258, 25);
            this.toolStripCategories.TabIndex = 6;
            this.toolStripCategories.Text = "toolStrip1";
            this.tsbAddCategory.DisplayStyle = ToolStripItemDisplayStyle.Text;
            this.tsbAddCategory.Image = (Image)componentResourceManager.GetObject("tsbAddCategory.Image");
            this.tsbAddCategory.ImageTransparentColor = Color.Magenta;
            this.tsbAddCategory.Name = "tsbAddCategory";
            this.tsbAddCategory.Size = new Size(33, 22);
            this.tsbAddCategory.Text = "Add";
            this.tsbAddCategory.Click += new EventHandler(this.tsbAddCategory_Click);
            this.tsbEditCategory.DisplayStyle = ToolStripItemDisplayStyle.Text;
            this.tsbEditCategory.Enabled = false;
            this.tsbEditCategory.Image = (Image)componentResourceManager.GetObject("tsbEditCategory.Image");
            this.tsbEditCategory.ImageTransparentColor = Color.Magenta;
            this.tsbEditCategory.Name = "tsbEditCategory";
            this.tsbEditCategory.Size = new Size(31, 22);


And it keeps giving me this error.

Warning 1 The variable 'componentResourceManager' is either undeclared or was never assigned.

I dunno what am doing wrong. Please help
Posted
Updated 16-May-11 23:03pm
v2
Comments
Ankur\m/ 17-May-11 7:40am    
What is not working? Does it give any error after you added the code that I gave you?

That looks like a Typo. Try ComponentResourceManager with a capital C at the front.

Hope this helps
 
Share this answer
 
Comments
parmar_punit 17-May-11 5:30am    
yes..
ComponentResourceManager is a class and as per the Naming convention that .Net Framework is follow, for the class name they use Pascal naming convention.
Patoh58 17-May-11 5:33am    
Wayne it gives off an error
An object reference is required for the non-static field, method, or property 'System.Resources.ResourceManager.GetObject(string)' if ts a small c then the one above is a warning
Sergey Alexandrovich Kryukov 17-May-11 17:33pm    
My 5. It would not compile then. Error report is wrong.
--SA
Warning?! It should give you a compilation error!

As Wayne already said, ComponentResourceManager is a class and starts with a capital C.

Patoh58 wrote:
An object reference is required for the non-static field, method, or property 'System.Resources.ResourceManager.GetObject(string)' if ts a small c then the one above is a warning

GetObject is an instance method of ComponentResourceManager. You need an instance of the class to access this method, which you seem to have not created.

Add this line:
C#
ComponentResourceManager componentResourceManager = new componentResourceManager();
//or the other overload passing Type as a parameter

now this line makes sense,
C#
componentResourceManager.GetObject("tsbAddCategory.Image");


For more information about the class, check the MSDN link - ComponentResourceManager Class[^]

Hope this helps! :thumbsup:
 
Share this answer
 
Comments
Patoh58 17-May-11 8:32am    
Here's the error it gives :
Error 44 'ConsultingLeadsPro.MainForm.componentResourceManager' is a 'field' but is used like a 'type'
Patoh58 17-May-11 8:39am    
private void InitializeComponent()
{
ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(MainForm));
this.btnSearch = new Button();
this.btnStop = new Button();
this.cmbSite = new ComboBox();
this.dtpLowDate = new DateTimePicker();
Ankur\m/ 17-May-11 8:41am    
I was just going to ask you to paste the code where error is occurring. Let me check.
Ankur\m/ 17-May-11 8:44am    
ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(MainForm));
I am afraid you cannot do that inside InitializeComponent() method.
Patoh58 17-May-11 11:05am    
Ok! Where can i put it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900