Form1, object or class?

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

So, I'm playing around with VB and tries to get the hang things.
When I add a form to my application, and I begin to add code to the form, it
stars with " Public Class form1"
But is Form1 a class on its own or is it an object based on the form class
in the framework?

What I guess I'm asking is if I treat Form1 as a class or an object derived
from a class.

/A.
 
So, I'm playing around with VB and tries to get the hang things.
When I add a form to my application, and I begin to add code to the form, it
stars with " Public Class form1"
But is Form1 a class on its own or is it an object based on the form class
in the framework?

What I guess I'm asking is if I treat Form1 as a class or an object derived
from a class.

/A.

If you were to combine the partial class structure of Form1 you would
have:

Public Class Form1
Inherits System.Windows.Forms.Form

End Class

So Form1 is a class that is derived from the Form class. So it has all
the properties and methods of the Form class, plus whichever ones you
add in.

Thanks,

Seth Rowe
 
If you were to combine the partial class structure of Form1 you would
have:

Public Class Form1
Inherits System.Windows.Forms.Form

End Class

So Form1 is a class that is derived from the Form class. So it has all
the properties and methods of the Form class, plus whichever ones you
add in.

Okey, but when is an object instanceiated from the Form1 class?
I thought the idea here was to define classed, and then generate an object
based on that class. Doesn't that actually mean that I only work directly on
the class?

/A.
 
Okey, but when is an object instanceiated from the Form1 class?
I thought the idea here was to define classed, and then generate an object
based on that class. Doesn't that actually mean that I only work directly on
the class?

/A.

Well, this is one of the areas that I don't like the implementation of
VB compared to C#. I realize you might not know much about C#, but you
should be able to figure out the following sample.

Here is how program startup is handled by C# - this is the class that
is the starting point of a generic window's application:

static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}

The last line is the one we are concerned with. This is where the
instantiation of the Form1 class occurs, and the Application.Run sets
a blocking call waiting for the closing of the Form1 instance before
it allows the actual program to exit. These details are pretty much
hidden in Visual Basic when you set the startup object as a form. All
the above is done implicitly and behind the scenes, but Form1 is being
instantiated and used, so even though it might seem like you are
working directly on a class, you are really working on the implicitly
created instance.

Thanks,

Seth Rowe
 
Back
Top