Windows Develop Bookmark and Share   
 index > Windows Forms General > Implimenting user controls - Missing assembly reference?
 

Implimenting user controls - Missing assembly reference?

I am new to user controls.

I created a user control (of severals controls) in my project so that I can use the same pattern of controls on multiple forms.

After building, it was automatically added into my toolbox. I dragged it onto my form.

When trying to assign text to one of the labels the control contains I did not get intellisense. Here is my code

HIP2007.ctlCustProjContr1.lblProject.Text = "Test";

When I attempt to build the application I receive the following error: “The type or namespace name ‘ctlCustProjContr1�does not exist in the namespace ‘HIP2007�(are you missing an assembly reference?)�/font>

What does this mean?

The user control, as well as the form on which it is placed, *are* in the same project and in the same namespace ‘HIP2007�

What kind of assembly reference is it asking for? What am I missing?

dbuchanan  Saturday, March 17, 2007 3:53 AM
Set the Modifier property to Public. Cleaner: add a public property to the control whose accessors reference the label control.
nobugz  Sunday, March 18, 2007 3:05 PM

The way you are using HIP2007 is incorrect, your usage implies you are trying to access a type inside the namespace when in practice you are actually trying to assign to a instance. So just remove the HIP2007 from the front of the code and it should compile just fine.

Phil Wright
Free user interface controls for Windows.Forms
http://www.componentfactory.com

Philip Wright  Sunday, March 18, 2007 7:33 AM

Ausing HIP2007 is

Adding the HIP2007 was one of my attempts to resolve a previous problem.

The conttrol is not recognized. When entered it as

lblProject.Text = "Test";

Intellisense did not work and I got this error when trying to compile:

Error 1 The name 'lblProject' does not exist in the current context C:\Users\dbuchanan.CBACONSULTINGSE\Documents\HIP2007\HIP2007\Forms - 01 Layout\ManageTasks.cs 22 13 HIP2007

Next I tried

ctlCustProjContr1.lblProject.Text = "Test";

Intellisense still did not work and I got this error:

Error 1 'HIP2007.ctlCustProjContr.lblProject' is inaccessible due to its protection level C:\Users\dbuchanan.CBACONSULTINGSE\Documents\HIP2007\HIP2007\Forms - 01 Layout\ManageTasks.cs 21 31 HIP2007

The control is there, and the modifier is set to "Protected"

What is the problem and solution to this?

dbuchanan  Sunday, March 18, 2007 2:36 PM
Set the Modifier property to Public. Cleaner: add a public property to the control whose accessors reference the label control.
nobugz  Sunday, March 18, 2007 3:05 PM

That was the answer. Thank you so much for your help with this!

Sometimes it is frustrating what lengths one has to go in an attempt todiscover how to implement what one would think should be a clearly documented feature. Perhaps I overlooked something, but it was not because I didn't look. Is there a secret to discovering such things?

dbuchanan  Sunday, March 18, 2007 8:02 PM
Not really. Understanding member access modifiers will get you there. Protected members are only accessible by derived classes. Your form cannot access the protected user control members since it doesn't derive from the user control you created, it derives from the Form class.
nobugz  Sunday, March 18, 2007 8:31 PM
Thank you. That explaination was very helpful because I got me thinkin what the difference was between using a base class form as conpared to using a user control.
dbuchanan  Sunday, March 18, 2007 9:48 PM

You can use google to search for other answers

Custom Search

More Threads

• Possible leak with TreeView Control
• How to create Undo/Redo functionality
• Need help with FSWatcher Event
• Best practice: skinning?
• problem: Drawing disappears!!
• Automated Printer Install
• What can I know what component is getting focus?
• How long it takes to develop an accounting Application?
• Disposed Object and Passing values from one form to another. (VC# 2005)
• a small problem with forms...