Namespace and InitializeComponent()

JimmyFo

Member
Joined
Aug 15, 2005
Messages
13
Programming Experience
1-3
Hi, I have a simple windows form. The form is named Container.vb and inside it is a class. When I put it in a namespace like so:

VB.NET:
[/COLOR][SIZE=2]
[COLOR=black]Namespace[/COLOR][/SIZE][SIZE=2][COLOR=black] Shell.UI[/COLOR]
[/SIZE][COLOR=black][SIZE=2]Public[/SIZE][SIZE=2] [/SIZE][SIZE=2]Class[/SIZE][SIZE=2] Container : [/SIZE][SIZE=2]Inherits[/SIZE][/COLOR][SIZE=2][COLOR=black] System.Windows.Forms.Form[/COLOR]
[/SIZE][COLOR=black][SIZE=2]Private[/SIZE][SIZE=2] parentWorkItem [/SIZE][SIZE=2]As[/SIZE][/COLOR][SIZE=2][COLOR=black] Shell.UI.Workitems.Workitems[/COLOR]
[COLOR=black]<InjectionConstructor()> _[/COLOR]
[/SIZE][COLOR=black][SIZE=2]Public[/SIZE][SIZE=2] [/SIZE][SIZE=2]Sub[/SIZE][SIZE=2] [/SIZE][SIZE=2]New[/SIZE][SIZE=2](<ServiceDependency()> [/SIZE][SIZE=2]ByVal[/SIZE][SIZE=2] workItem [/SIZE][SIZE=2]As[/SIZE][SIZE=2] WorkItem, [/SIZE][SIZE=2]ByVal[/SIZE][SIZE=2] workItemTypeCatalog [/SIZE][SIZE=2]As[/SIZE][/COLOR][SIZE=2][COLOR=black] IWorkItemTypeCatalogService)[/COLOR]
[/SIZE][SIZE=2][COLOR=black]Try[/COLOR]
[/SIZE][SIZE=2][COLOR=black]InitializeComponent()[/COLOR]
[/SIZE][SIZE=2][COLOR=black]Me[/COLOR][/SIZE][SIZE=2][COLOR=black].parentWorkItem = workItem[/COLOR]
[/SIZE][SIZE=2][COLOR=black]Catch[/COLOR]
[/SIZE][SIZE=2][/SIZE][COLOR=black][SIZE=2]End[/SIZE][SIZE=2] [/SIZE][SIZE=2]Try
[/SIZE][/COLOR][SIZE=2][/SIZE][COLOR=black][SIZE=2]End[/SIZE][SIZE=2] [/SIZE][SIZE=2]Sub
[/SIZE][/COLOR][SIZE=2][/SIZE][COLOR=black][SIZE=2]End[/SIZE][SIZE=2] [/SIZE][/COLOR][SIZE=2][COLOR=black]Class[/COLOR]
[COLOR=black]End[/COLOR][/SIZE][COLOR=black][SIZE=2] [/SIZE][SIZE=2]Namespace
[/SIZE]


it doesn't work, it says: Error 1 Name 'InitializeComponent' is not declared.

If I remove the namespace, I get this:

Error 2 'Container' is a type in 'SmartClient' and cannot be used as an expression.

Ideas?

Thanks!
James
 
hehehe..... I feel your pain.... went through the same problem.... in your Solution Explorer, make sure you have the project set to Show all Files.... then under your form... expand the node... you should see two files under that form.... open the .designer.vb in code mode.... add your namespace to the top.

For some reason VS isn't very good at adding the namespace to all of the dependent files. What's happened is that your code is now in one namespace, while theInitializeComponent sub is a different namespace.

-tg
 
Hey thanks, that got rid of that error! Unfortunately, it then brought back the other one:

Error 1 'Container' is not a member of 'ShellContainer'.

The code it references is in Application.Designer.vb

If I change it from

VB.NET:
[SIZE=2][COLOR=#0000ff]
Me[/COLOR][/SIZE][SIZE=2].MainForm = [/SIZE][SIZE=2][COLOR=#0000ff]Global[/COLOR][/SIZE][SIZE=2].ShellContainer.Container
[/SIZE]

to

VB.NET:
[SIZE=2][COLOR=#0000ff]
Me[/COLOR][/SIZE][SIZE=2].MainForm = [/SIZE][SIZE=2][COLOR=#0000ff]Global[/COLOR][/SIZE][SIZE=2].ShellContainer.Shell.UI.Container.ActiveForm
[/SIZE]

it works, where ShellContainer is the project, and "Shell.UI" is the namespace.

Is this right? I know this data is auto generated and as such shouldn't be changed.

Thanks,
James
 
Back
Top