form inheritence

M

Mr. X.

Hello.
I have an inherited windows-form class : MyForm.
When I put component on it - I see many code behind (and when I do on a
original windows form, I don't get an automatic code behind).

Form is declared :
Public Class MyForm
Inherits Form

Public Sub New()
MyClass.New(Nothing)
End Sub

Public Sub New(ByRef dt As DataTable)
MyBase.New()
...
End Sub
End Class

When I do another form like this (It is declared as a class) :
Public Class frmTest
Inherits MyForm
....


When I just put a button on the form I get a auto-generated source on the
code :

Friend WithEvents Button1 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(506, 83)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(67, 58)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'frmTest
'
Me.ClientSize = New System.Drawing.Size(744, 218)
Me.Controls.Add(Me.Button1)
Me.Name = "frmTest"
Me.ResumeLayout(False)

End Sub

Why I getting that automatic code, and how can I avid getting the
auto-generated code behind (or see it elsewhere) ?

Thanks :)
 
A

Armin Zingler

Am 26.04.2010 00:48, schrieb Mr. X.:
Why I getting that automatic code, and how can I avid getting the
auto-generated code behind (or see it elsewhere) ?

You always get the automatic code, but by default it's in the *.Designer.vb file.
Show "all files" in the solution explorer (click the icon at the top) and you'll
see a "+" sign in front of "form1.vb". Open it to see the designer file.

Without using the Form template, the automatic code is always put in your
own class file. I don't know how the designer finds out where to put it,
so I can't tell you if it were possible to force him to put it somewhere
else.
 
M

Mr. X.

For the new form I don't get the code in *.Designer.vb, but on the
myForm.vb itself
Is there any way to declare there is a designer behind (another vb) ?

Thanks :)
 
F

Family Tree Mike

Am 26.04.2010 01:52, schrieb Mr. X.:

From experimenting, it looks like you just need to add a class file,
named MyForm.Designer.vb, modfied as such:

partial class MyForm
Inherits System.Windows.Forms.Form

Private Sub InitializeComponent()
end sub
end class

The desinger canvas appears to just try and find the Initialize
component file and update that.
 
C

Cor Ligthert[MVP]

What you see is the behaviour as it is for all versions of Net including Net
1.x.

The partial classes started at version 2.0, the designer templates generate
the designer.vb like it is with all this kind of generated classes (DataSet,
component, etc).
 
M

Mr. X.

:
---------------------------------
....
partial class MyForm
Inherits System.Windows.Forms.Form

Private Sub InitializeComponent()
end sub
end class

The desinger canvas appears to just try and find the Initialize component
file and update that.

Hmm.
Seems too be very good solution - Thanks ...

I did that, but :
1. Still, when new controls, such as button, that are dropped onto the
form - new auto-generated code is on the myForm.vb code,
and not myForm.Designer.vb

2. How can I see the myForm.Designer.vb, if it is not shown on solution
explorer ?

Thanks :)
 
F

Family Tree Mike

:
---------------------------------
...

Hmm.
Seems too be very good solution - Thanks ...

I did that, but :
1. Still, when new controls, such as button, that are dropped onto the
form - new auto-generated code is on the myForm.vb code,
and not myForm.Designer.vb

2. How can I see the myForm.Designer.vb, if it is not shown on solution
explorer ?

Thanks :)

Maybe manually fixing the .designer is a capability only in VS 2010
then. That's what I'm using. I will say that I created the .Designer
file before adding controls. Maybe you added some first?

Regarding seeing the .Designer.vb files, Armin already suggested an
answer. But, in the solution explorer, for me, the second button at the
top left is the "Show All Files" toggle button. It looks like three
pages of paper on a button. This enables the + or > depending on the
version of Visual Studio.
 
M

Mr. X.

O.K.
(I have VS 2008)
Problem solved by the following way (not an elegant solution, anyway, and if
someone has other elegant way, I would like to hear about ...) :

What I did is simple, but I didn't find any other way :
Created a new form (not myForm, but a windows-form), put buttons on it, and
other components.
I get into the designer (I am searching the definition of initComponent
method, and didn't find other way), and only change the line :
Inherits System.Windows.Forms.Form
to :
Inherits MyForm.

Because MyForm is a child of System.Windows.Forms.Form, everything was
compiled fine, and also worked fine.

Thanks :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top