Is this Normal?

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I created a windows form class name myForm, and a 2nd class vb file
with a partial class myform. The goal was to separate non-GUI
properties and methods from the main form into its own file because it
can be used by others.

In the IDE, this 2nd file will display as a empty form.

Q1) Is that normal?

I don't think its normal. If you accidentally click on this empty form
to create the load event, then you compiler errors and if you
manually try to correct it by deleting the events, you get designer
errors.

Q2) Is what I did with a form partial class possible or should I do it
another way?
TIA

--
 
I created a windows form class name myForm, and a 2nd class vb file
with a partial class myform.  The goal was to separate non-GUI
properties and methods from the main form into its own file because it
can be used by others.

In the IDE, this 2nd file will display as a empty form.

Q1) Is that normal?

I don't think its normal. If you accidentally click on this empty form
   to create the load event, then you compiler errors and if you
manually try to correct it by deleting the events, you get designer
errors.

Q2) Is what I did with a form partial class possible or should I do it
another way?

Starting with VS2005, that ius the default way the IDE creates a new
windows form.

Create a new form the usual way. Select the form and click on the
"Show All Files" button. You will see a plus sign appear next to the
form. Click on it and you will now see a module named <your form
name>.Designer.vb. It is the partial class that contains all of the
designer code for the form.
 
Starting with VS2005, that ius the default way the IDE creates a new
windows form.

Create a new form the usual way. Select the form and click on the
"Show All Files" button. You will see a plus sign appear next to the
form. Click on it and you will now see a module named <your form
name>.Designer.vb. It is the partial class that contains all of the
designer code for the form.

That means sense now. But is odd because I did not "notice" the 2nd
one show up as a form. I was working on this for a few days because it
was noticed double clicking on the 2nd file to view the code. when the
empty form came up, it surprise me.

I see the 1st form designer has an attribute:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class WildcatLoginForm

Maybe there is an attribute I can add to the 2nd one to disable the
Designer for it?

I am currently working on the organization (something I had to do at
some point) but I need to get a better handle of namespaces, My, Me,
MyBase, etc.

Our frameworks allows for console and GUI login, so there is a base
class that I want to be used for all cases. So it was probably a bad
idea to use partial class for the base class with the same name as the
form. The problem (and I figure i would address this later one I
begin the final organization) was exposing functions. For example, in
the form:

Public Class WildcatLoginForm

Public Settings As New LoginSettings
Public NotInheritable Class LoginSettings
Default Property Self(ByVal name As String) As Object
Get
Return My.Settings(name)
End Get
Set(ByVal value As Object)
My.Settings(name) = value
My.Settings.Save()
End Set
End Property
End Class

Private Sub btnLogin_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles cmdLogin.Click

... validate fields...

If Not ConnectUser() Then
Return
End If
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub

End Class

What I had in the partial WildcatLoginForm was the ConnectUser() and
other non-gui functions. The partial also had access to the field
property bound My.Settings via LoginSettings class. So it worked
nicely and when I did this, there was no empty form. So its odd. :-)

But I am sure there is better organization and naming I can work out
than using a partial here.

--
 
Mike said:
I created a windows form class name myForm, and a 2nd class vb file with
a partial class myform. The goal was to separate non-GUI properties and
methods from the main form into its own file because it can be used by
others.

In the IDE, this 2nd file will display as a empty form.

Q1) Is that normal?

I don't think its normal. If you accidentally click on this empty form
to create the load event, then you compiler errors and if you manually
try to correct it by deleting the events, you get designer errors.

SOLVED! I knew I wasn't crazy. I will chalk this one as a IDE bug :-)

Like I said, when I first created the helper 2nd class vb file with
the partial class of the form, the IDE did not view this as a form and
show it as an empty form to display.

The reason is that I had NON-PARTIAL class at the top of the file that
I was first using to explore separating the non-gui functionality from
the main form.vb file. That is when I added the partial class
myform right below it and all was working fine.

I must of removed this temporary class yesterday during a clean up
process so now the first class at the top was the partial class
MyForm. Then it began to look as a form to the IDE.

In starting a reorganization just a few minutes ago, I added a Public
Class at the top and PUFF - the IDE immediately removed the form
status of this file!!

Go figure!

--
 
Back
Top