Can you edit auto generated Partial Class Designer VB code?

  • Thread starter Thread starter Mike
  • Start date Start date
Mike said:
-snip-
Thanks J.B.

It appears to me that you can cut out all but the private component
member and the InitializeComponent() function and paste the new and
dispose functions into the main component class.

So the .Designer.vb code only really needs this:

The Designer.vb file can be eliminated entirely. I'd have to actually
try it to find out if it can both exist AND not contain any of the
auto-generated code. But I'd be inclined to say yes, with the caveat
that if it exists it's obviously going to be the preferred place to
place control declarations and the InitializeComponent sub (and that
both are entirely recreated whenever there is a change to the form).

I have one more comment on editing the auto-gnerated code. You're
asking about editing AROUND the auto-generated code, not only can you
edit around the auto-generated code, you can edit the auto-generated
code itself, but beware when doing so: the auto-generated code is both
destination AND source. Changes made to it WILL show up when you open
the designer and if you mess it up enough, you WON'T be able to fix it
through the designer.
 
J.B. Moreno said:
The Designer.vb file can be eliminated entirely. I'd have to actually
try it to find out if it can both exist AND not contain any of the
auto-generated code. But I'd be inclined to say yes, with the caveat
that if it exists it's obviously going to be the preferred place to
place control declarations and the InitializeComponent sub (and that
both are entirely recreated whenever there is a change to the form).

I have one more comment on editing the auto-gnerated code. You're
asking about editing AROUND the auto-generated code, not only can you
edit around the auto-generated code, you can edit the auto-generated
code itself, but beware when doing so: the auto-generated code is both
destination AND source. Changes made to it WILL show up when you open
the designer and if you mess it up enough, you WON'T be able to fix it
through the designer.

Its safer to just leave things as expected and do it programmatically
if all possible.

I want to study nested classes. Something like this offers
constructor/destructor logic to the component class:

Public Class MyComponent
Private nestedObject as new Constructor
Public class Constructor
public sub new()
end sub
protected overrides sub finalize()
end sub
End Class
End Class

When MyComponent is instantiated, it will initialized its members.
Thus the nested Constructor class is instantiated preparing a New()
and Finalize(). Finalize() will be called here.

Make sense?

--
 
J.B. Moreno said:
The Designer.vb file can be eliminated entirely. I'd have to actually
try it to find out if it can both exist AND not contain any of the
auto-generated code. But I'd be inclined to say yes, with the caveat
that if it exists it's obviously going to be the preferred place to
place control declarations and the InitializeComponent sub (and that
both are entirely recreated whenever there is a change to the form).

I have one more comment on editing the auto-gnerated code. You're
asking about editing AROUND the auto-generated code, not only can you
edit around the auto-generated code, you can edit the auto-generated
code itself, but beware when doing so: the auto-generated code is both
destination AND source. Changes made to it WILL show up when you open
the designer and if you mess it up enough, you WON'T be able to fix it
through the designer.

Its safer to just leave things as expected and do it programmatically
if all possible.

I want to study nested classes. Something like this offers
constructor/destructor logic to the component class:

Public Class MyComponent
Private nestedObject as new Constructor
Public class Constructor
public sub new()
end sub
protected overrides sub finalize()
end sub
End Class
End Class

When MyComponent is instantiated, it will initialized its members.
Thus the nested Constructor class is instantiated preparing a New()
and Finalize(). Finalize() will be called here.

Make sense?

--
 
Mike said:
I want to study nested classes. Something like this offers
constructor/destructor logic to the component class:

Public Class MyComponent
Private nestedObject as new Constructor
Public class Constructor
public sub new()
end sub
protected overrides sub finalize()
end sub
End Class
End Class

When MyComponent is instantiated, it will initialized its members. Thus
the nested Constructor class is instantiated preparing a New() and
Finalize(). Finalize() will be called here.

Make sense?

--

Just found an entire MSDN section on the usage of nested classed for
components.

Nested Classes in Components
http://msdn.microsoft.com/en-us/library/cbwxw0ye(VS.71).aspx

After reading it, I think the improvement to the .Designer.vb class
that will help resolve this issue, making it less a concern whether
you can edit or not the .designer.vb code is for the generated code
template to add a empty inheritable "destructor" or Delete() that is
called by the dispose method.

That is what i did for my SDK abstract class.

Public Class CWildcatAbstract
Implements IDisposable

Private _disposed As Boolean = False

Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub

Protected Overloads Overridable Sub Dispose(disposing As Boolean)
If Not _disposed Then
If disposing Then
' add releasing of managed resources
_disposed = true
End If
' add releasing of unmanaged resources
Delete()
_disposed = True

End If
End Sub

Protected Overrides Sub Finalize()
Dispose(False)
End Sub

Public Overridable Function Delete() as boolean
return false
end function

End Class

So now a class that inherits this can create a Delete method that will
be called come destruction/cleanup time.

Public Class CWildcat : inherits CWildcatAbstract

Public Overrides Function Delete() as boolean
... do whatever cleanup ...
return true
end function
End class

--
 
Mike said:
I want to study nested classes. Something like this offers
constructor/destructor logic to the component class:

Public Class MyComponent
Private nestedObject as new Constructor
Public class Constructor
public sub new()
end sub
protected overrides sub finalize()
end sub
End Class
End Class

When MyComponent is instantiated, it will initialized its members. Thus
the nested Constructor class is instantiated preparing a New() and
Finalize(). Finalize() will be called here.

Make sense?

--

Just found an entire MSDN section on the usage of nested classed for
components.

Nested Classes in Components
http://msdn.microsoft.com/en-us/library/cbwxw0ye(VS.71).aspx

After reading it, I think the improvement to the .Designer.vb class
that will help resolve this issue, making it less a concern whether
you can edit or not the .designer.vb code is for the generated code
template to add a empty inheritable "destructor" or Delete() that is
called by the dispose method.

That is what i did for my SDK abstract class.

Public Class CWildcatAbstract
Implements IDisposable

Private _disposed As Boolean = False

Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub

Protected Overloads Overridable Sub Dispose(disposing As Boolean)
If Not _disposed Then
If disposing Then
' add releasing of managed resources
_disposed = true
End If
' add releasing of unmanaged resources
Delete()
_disposed = True

End If
End Sub

Protected Overrides Sub Finalize()
Dispose(False)
End Sub

Public Overridable Function Delete() as boolean
return false
end function

End Class

So now a class that inherits this can create a Delete method that will
be called come destruction/cleanup time.

Public Class CWildcat : inherits CWildcatAbstract

Public Overrides Function Delete() as boolean
... do whatever cleanup ...
return true
end function
End class

--
 
Mike said:
Just found an entire MSDN section on the usage of nested classed for
components.

Nested Classes in Components
http://msdn.microsoft.com/en-us/library/cbwxw0ye(VS.71).aspx

After reading it, I think the improvement to the .Designer.vb class that
will help resolve this issue, making it less a concern whether you can
edit or not the .designer.vb code is for the generated code template to
add a empty inheritable "destructor" or Delete() that is called by the
dispose method.

...

So now a class that inherits this can create a Delete method that will
be called come destruction/cleanup time.

Public Class CWildcat : inherits CWildcatAbstract

Public Overrides Function Delete() as boolean
... do whatever cleanup ...
return true
end function
End class

--

HA!

Well folks, the above is what C# does when you create a COMPONENT!

It puts the constructors in the main component class and in the
..designer.cs file it just has the stuff creating and initializing the
component. This is how the VB.NET component creation should be as
well. Apparently, the VB.NET design team folks did not catch up with
the c# design team folks on this one.

One solution is to change the templates in:

Common7\IDE\ItemTemplatesCache\VisualBasic\1033\Component.zip\Component.Designer.vb
Common7\IDE\ItemTemplatesCache\VisualBasic\1033\Component.zip\Component.vb

or create new templates that exposes the constructor, destructors to
the main componentclass.

----
 
Mike said:
Just found an entire MSDN section on the usage of nested classed for
components.

Nested Classes in Components
http://msdn.microsoft.com/en-us/library/cbwxw0ye(VS.71).aspx

After reading it, I think the improvement to the .Designer.vb class that
will help resolve this issue, making it less a concern whether you can
edit or not the .designer.vb code is for the generated code template to
add a empty inheritable "destructor" or Delete() that is called by the
dispose method.

...

So now a class that inherits this can create a Delete method that will
be called come destruction/cleanup time.

Public Class CWildcat : inherits CWildcatAbstract

Public Overrides Function Delete() as boolean
... do whatever cleanup ...
return true
end function
End class

--

HA!

Well folks, the above is what C# does when you create a COMPONENT!

It puts the constructors in the main component class and in the
..designer.cs file it just has the stuff creating and initializing the
component. This is how the VB.NET component creation should be as
well. Apparently, the VB.NET design team folks did not catch up with
the c# design team folks on this one.

One solution is to change the templates in:

Common7\IDE\ItemTemplatesCache\VisualBasic\1033\Component.zip\Component.Designer.vb
Common7\IDE\ItemTemplatesCache\VisualBasic\1033\Component.zip\Component.vb

or create new templates that exposes the constructor, destructors to
the main componentclass.

----
 
Back
Top