views:

827

answers:

3

In a Visual Basic project, I created a homemade TabControl in order to fix a visual bug. The control works properly, however whenever I modify the form using my tab, Visual Studio adds MyProject in front of the control in its declaration:

Me.tabMenu = New MyProject.MyClass 'Gives a BC30002 compile error

If I remove the MyProject., the project compiles properly.

MyClass is in a separate file MyClass.vb and looks mostly like this:

Public Class MyClass
Inherits System.Windows.Forms.TabControl

Public Sub New()
    InitializeComponent()
    MyBase.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed
End Sub

Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
    //OnDrawItem code
End Sub

Private Sub My_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Me.DrawItem
    //My_DrawItem code
End Sub
End Class

I tried removing the file and adding it again, copy and pasting the class inside MyForm.designer.vb, adding MyProject. to the class name, but nothing stopped Visual Studio from adding this so-hated MyProject.

Edit regarding this answer:

I understand the thing about the namespace, however my problem is mostly that the compiler does not recognize the class with the project name appended but still adds it everytime.

A: 

By default, Visual Basic .NET assigned a default namespace to your project. (I believe the default is, in fact, MyProject.)

This is what's being prepended, and it's being done to explicitly identify your class in the designer.

No matter what your default namespace is for your project, the WinForms designer will add the namespace name to the .designer.vb file.

To change the default namespace, go to your project properties; it should appear on the first tab.

Also, generally, don't modify the .designer.vb files if you can avoid it. Those files get completely blown away and rebuilt by Visual Studio often, so your changes will more likely than not be eliminated.

John Rudy
A: 

What is the actual compile error you are getting? Is it possable that the VB compiler is interpreting MyProject as something other than a namespace identifier? You could also try changing the default namespace for the project, then see what it does, it might give you a hint as to what the actual problem is. You could also try changing the offending line to

Me.tabMenu = New Global.MyProject.MyClass

then let us know what the results are.

pipTheGeek
A: 

I've seen this before when you have a public module with the same name as your default namespace (project name). If that's the case, either rename the module or the default namespace and the problem should go away,.

Joel Coehoorn