Question Information about class About in NET 3.5

gs99

Active member
Joined
May 8, 2010
Messages
42
Programming Experience
Beginner
(1) How do I display information about a class in NET?
A display of the whole class as if I had created it, with all the properties and methods.

(2) The specific class: About (a windows form template).

What I've tried (I have VB 2008 Express, NET 3.5):

In Visual Studio; F2 Object Browser, Selected NET 3.5, entered About in search.
Shows four items that don't appear to be the About class.

Went to
.NET Framework 3.5

Can not find About class.
Looked in each namespace in System.Windows.Forms
Search for "About" shows nothing helpful.

Is there a way to specify a class in either Object Browser or the MSDN site?

Any comments are welcome.
 
I figured this out.
I was doing a tutorial in which I added a Windows Form, About Box, and named it "About.vb".
When going back to that project a few days later, I thought "About" was a NET class. But the name "About" came from me, not from NET!

In Object Browser, set Browse to "My Solution".
Find my project, then click on my About class.
Bottom right displays information for this class that I had named:
Public NotInheritable Class About
Inherits System.Windows.Forms.Form
Member of F_Windows_Forms_Text_Editor

Clicking on the last "Form" there displays information about the class Form (a name provided by NET) that is inherited in the "About" class.

So it appears that there is no name assigned by NET to the class I utilized and named "About". This is a little confusing.

Going back to the Microsoft site, how do I search for information about the "About Box" class, which is different than a normal Form class?
 
My first question still needs an answer:
(1) How do I display information about a class in NET?
A display of the whole class as if I had created it, with all the properties and methods.

For example, the Form class has default Size 300 pixels in height and 300 pixels in width.

I assume that's done in the Constructor. What else is done there?
Is there a way to display this information?
Is there a restriction with Express edition?
 
In Object Browser, set Browse to "My Solution".
Find my project, then click on my About class.
Bottom right displays information for this class that I had named:
Public NotInheritable Class About
Object Browser displays informations about the members of the class, ie properties, fields, methods, events. You can filter which members is displayed in the Settings dropdown button. About form is as you see a regular form inherited from the 'plain' Form class, it adds no other public members.
(1) How do I display information about a class in NET?
A display of the whole class as if I had created it, with all the properties and methods.
All members, including private, can be seen in Object Browser. For source code only user code and generated code can be seen in Visual Studio. User code is where you write your code and is available with the 'View Code' option (main menu or context menu), the generated code is available from Solution Explorer if you click 'Show All Files' button, then you can expand any source object and view the code for the 'source.Designer.vb' file. For user code and generated code you can also doubleclick the member in Object Browser to display the source code.

It is also possible to read the code for the .Net Framework class library assemblies themselves, you have to use a special program called .Net Reflector for this. It is not something developers in general have any use for, unless you're at advanced level and have special interest in this.
 
1. What I was looking for is where (for example) the default size (300 x 300) is actually set for class Form.
Isn't that done in a constructor?
This is the Microsoft web site for Form class Constructor
Form Constructor (System.Windows.Forms)
Are we not supposed to learn from NET classes?

2. About Box
About form is as you see a regular form inherited from the 'plain' Form class, it adds no other public members.
From the VS Object Browser, I can see that "About" inherits from Form.
But it seems that About is not a "regular" form.
Some things I've noticed different than a normal Form:
> It starts "Public NotInheritable Class AboutBox1"
> It has specific layout defaults (columns and rows), and an image.
> It does not allow controls to be added.

Why didn't they make a separate About class?
 
What I was looking for is where (for example) the default size (300 x 300) is actually set for class Form.
Isn't that done in a constructor?
When they designed that template they did what you would when designing any form, the form size was set by adjusting it in Designer. Any changes you make in Designer causes code to be generated in the 'generated code' area. Specifically these property values are set in the generated InitializeComponent method.
From the VS Object Browser, I can see that "About" inherits from Form.
But it seems that About is not a "regular" form.
Some things I've noticed different than a normal Form:
> It starts "Public NotInheritable Class AboutBox1"
> It has specific layout defaults (columns and rows), and an image.
> It does not allow controls to be added.
NotInheritable means that they by design have prevented further inheritance of the AboutBox class.
It uses a common layout control called TableLayoutPanel. You can also use the TableLayoutPanel control in your forms. I have explained about this control in your other thread.
 
Your reply didn't use the word "constructor".

In tutorials about Classes, they say initial (default) values are defined in Class code called a Constructor, such as:
VB.NET:
Public Sub New()
    _iD = 0
    _description = String.Empty
    'other variable init goes here
End Sub
Found this comment in NET 3.5 Form.StartPosition Property:
"This property should be set in your form's constructor." Are they not talking about code such as above?
Where is the constructor code in NET Form class (e.g. StartPosition with value "WindowsDefaultLocation")?

When they designed that template they did what you would when designing any form, the form size was set by adjusting it in Designer.
Whatever is done in Designer must then be expressed in code.
When the Form1 template was designed, where is the resultant code for their design? How does it get passed on to me?

Specifically these property values are set in the generated InitializeComponent method.
I have Project "Show All Files" activated.
On a new Windows Application, Form1.Designer.vb includes this code:

VB.NET:
    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.Text = "Form1"
    End Sub
Where are all the default values stored?
Is this a restriction of Express Edition? I did mention that I have VB 2008 Express.
Am I looking at the right place?
After changing StartPosition to CenterScreen, the file shows:

VB.NET:
Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub

After changing Size to 350 x 350; the file shows:

VB.NET:
   Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(342, 316)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub

Note: Me.Text value is shown but Me.Size is not shown. Both are inherited from Control.

I don't see the results of Designer showing in InitializeComponent.

Obviously these things work OK. I'm just trying to organize my understanding.
 
Your reply didn't use the word "constructor".
Constructor. The form constructor calls InitializeComponent method, InitializeComponent method is where the generated code is serialized to to set up the thing you do using the visual designer. If you add another constructor (Sub New) to the form you will see the Designer automatically adds a call to InitializeComponent method also.
Found this comment in NET 3.5 Form.StartPosition Property:
"This property should be set in your form's constructor."
You should set this property in Designer. (Designer will add the code to InitializeComponent method, which is called from the forms constructor, yadda)
Where are all the default values stored?
Default values are those defined in the respective classes, only if changing a property to something different than the default value is it necessary to set that something using code (user/generated). The default values for any property is explained in the help documentation. In Properties window in Designer you can usually see non-default values as bolded text.
changing Size to 350 x 350; the file shows: ... but Me.Size is not shown
Designer sets ClientSize property to an appropriate value, this is the 'inner' size of the form, the space available to client controls.
 
If you add another constructor (Sub New) to the form you will see the Designer automatically adds a call to InitializeComponent method also.
I added a "Sub New()" to Form1; and yes - it inserted the call.
And no error message.
When I added a second "Sub New()" to Form1, there is an error message
'Public Sub New()' has multiple definitions with identical signatures.
So I conclude that the original (hidden) Form1 constructor has a different signature, one that has parameters?

I added a breakpoint at "Sub New()". When I ran the program, it stopped at the breakpoint.
Why would this sub be called? Wouldn't the original "Sub New" be called (I assume with parameters)?

When you say "add another constructor", you imply that one already exists.
Where is the first form constructor (Sub New) that calls InitializeComponent()?
This is what I've been looking for
A display of the whole class as if I had created it, with all the properties and methods.
including the constructor code.
Is that not available? If it's not, then OK. I'm just trying to learn about Class operation.
 
Where is the first form constructor (Sub New) that calls InitializeComponent()?
So I conclude that the original (hidden) Form1 constructor has a different signature, one that has parameters?
Why would this sub be called? Wouldn't the original "Sub New" be called?
Your form inherits Form class, which inherits multiple other classes down the hierarchy. Inherited classes may or may not add something to the construtor. All constructors from base Object type and up are called when the derived object is created.
A display of the whole class as if I had created it, with all the properties and methods.
As I said, the only way to see the internal .Net Framework code is to use .Net Reflector.
 
I see this in Reflector:

Class Form has Public Sub New() and Shared Sub New()
Class ContainerControl has Public Sub New() and Shared Sub New()
Class ScrollableControl has Public Sub New() and Shared Sub New()
Class Control has Public Sub New() and Shared Sub New()
Class Component has Public Sub New() and Shared Sub New()
Class MarshalByRefObject has Protected Sub New()

1. Why don't I see InitializeComponent() in any of these Sub New()?

2. How can there be two Sub New() in a class? Are they not identical signatures?
Apparently, "Shared" makes a difference?
But why am I able to add another Public Sub New() to Form1?

3. A class can call only one constructor, correct? (and Shared constructors)
So I still ask. If class Form already has Public Sub New() and Shared Sub New(), why does it visit Sub New() that I added?

4. Why doesn't Class MarshalByRefObject show "Inherits Object"?
 
1. You should be seeing the InitializeComponent call in the instance constructor.

2. Shared is different and makes a difference, true.

3. Do you see the calls you add to your constructor with Reflector? (yes). Do you also see other calls that you didn't put there? (yes) Where does these calls come from? Do you think it is possible they were added, ie generated, when assembly was compiled? (yes) These things are added and merged as seen fit. This has no implications for you as programmer. If you add and initialize a field in your form code you will for example also see that compiler moves the initialization calls to the constructor. IDE/compiler is helpful in that regard making things easier for the programmer, VB/.Net is full of such things that goes on under the hood (one example is how events really work with delegates), and more is to come as language/IDE evolves. One of the latest is in VB 2010 where you can declare a property only by its signature (just like a field) and compiler takes care of the rest adding the default private field and setter/getters, things one in default cases shouldn't need worry about and waste time writing, or later waste time reading loads of standard code that makes no practical difference.

4. All types derive from Object ultimately, you'll see the same thing for example for any common structure type in relation to ValueType class (and further to Object). This is at a point where class definitions and the defined type system meets.
 
You should be seeing the InitializeComponent call in the instance constructor.
No I don't.

Do you see the calls you add to your constructor with Reflector?
No.
Perhaps the reason I'm not seeing these things is - I have VB Express.
Reflector does not install as a plugin; it does not appear as a menu option. It works as a stand-alone app.
Therefore it may not have all the features that a plugin has.

This is what prompted my original questions:
When I create class MyClass, there are two basic things I need to do (in addition to the basic Class):
A. Insert constructor code in the Class - Sub New()
B. Instantiate an object of the class - Dim objClass as New MyClass

However, when starting a new Windows Application, VS generates class Form1 for me.
Form1.vb has code for the basic class; I can see it:

VB.NET:
Public Class Form1

End Class
What I cannot see are steps A and B.

If I do not write constructor code, VS inserts a simple constructor:
VB.NET:
Public Sub New()
End Sub
But this is not visible.
If I visibly add constructor code of my own, the phantom Sub New() evidently is deleted.

So the answer to my question could be stated:
VS inserts invisible A and B code for a Windows Form. VS also generates code for my Designer changes; that code is seen in the App.Designer.vb file (Show All Files turned on).

VS does many things under the hood to make everything work.
Don't worry; be happy!

If I need to know more about NET things, I'll need to upgrade my Visual Studio.

Some questions were not answered; but I can proceed to other subjects now.

Thanks again for your explanations!
 
No I don't.
No.
Perhaps the reason I'm not seeing these things is - I have VB Express.
Reflector does not install as a plugin; it does not appear as a menu option. It works as a stand-alone app.
Therefore it may not have all the features that a plugin has.
No difference, you must be looking the wrong place, or haven't loaded the latest version of the compiled assembly. For example if you load the assembly, then add changes and compile, you must refresh Reflector to load latest.
If I need to know more about NET things, I'll need to upgrade my Visual Studio.
I don't see why, there is no difference in these matters for any VS version.
VS does many things under the hood to make everything work.
None of which conflicts with anything you may or want to do ;)
 
No difference, you must be looking the wrong place

Their readme.rtf file does not say "Reflector does not run in Express."

The instructions:
Run Reflector.exe. The next time you open Visual Studio, .NET Reflector will be available in the menu bar.

But when I run Reflector.exe, it displays info from NET; it does not enable an addin to VS. It does not appear in VS menu.

In my Reflector Tools, Integration Options, it shows:
Visual Studio Integration
Select to add the Visual Studio add-in:
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
All three versions are dimmed, indicating that Reflector does not recognize Visual Studio Express.

In their forum they say Express does not work with Reflector.
Red Gate forums :: View topic - Multiple Versions of VS Installed

Evidently, it does work different with Express. Perhaps other Express users can confirm this.

Therefore , it seems I would need to purchase VS for Reflector to work as an addin with my applications.
 
Back
Top