What is Form Name

GrexD

Well-known member
Joined
Mar 5, 2008
Messages
95
Programming Experience
Beginner
I started a new project and had a Form named Form1. Later I renamed it frmMain. I have tabs listed as "frmMain[Design] and frmMain
VB.NET:
Expand Collapse Copy
. In the solution explorer it list frmMain.vb and frmMain.resX. When I try to access frmMain properties or objects from another form vb.net acts like it doesn't exit. 

On the Project Properties Application tab, sure enough the Start Up Object is still listed as Form1 and at the top of the code window is says "Friend Class Form1". So frmMain is the file name but I can't, for the life of me, figure out how to make it the object name. The properties window for the form only has file name and location.

What the heck am I missing.

Greg
 
Select the form in Designer and change the "(Name)" property.

The name you changed in Solution explorer is the file name, which may contain several classes and such.
 
Thanks.

I know I've changed the name of a form in past projects and did not have to seek out the property in the designer, or at least I think have. I'm maintaining applications in VB6, VB.Net, and Access VBA. Sometimes I forget which flavor of the language I'm in.

This begs the question: Why can I change the name of a Form in the properties window. Is this a "feature" or is there some reason for it?

Greg
 
Actually, when testing now, I see that changing the "File Name" property either in Solution Explorer or Properties window when a file node is selected also changes the form class name when this name is the same. If I change the class name in Properties window when the form class is selected in Design view the file name does not change and the names is out of sync. If I then change file name the class name is not sync'ed to same name. Mind you I'm using VB 2008, I can't remember the exact behaviour for this in VB 2005 IDE, I obviously had the impression these two names had no relation, but perhaps that was in VB 2003...
 
Yeah, something is still not right here. I changed the Name property in the designer and it seemed to work. I had mucked up a lot of stuff so I closed the project with out saving and tried it again after re-opening the project. The Class = Form1; Me.Name = "frmMain", but I must access the form with Form1.{ControlName}

This was a single form project supplied by the developer of an OCX control I bought for the company I work for. It was a VB.net project but it looks like they just ported a VB6 app because I have code like this in the designer...

VB.NET:
Expand Collapse Copy
    Private Shared m_vb6FormDefInstance As Form1
    Private Shared m_InitializingDefInstance As Boolean
    Public Shared Property DefInstance() As Form1
        Get
            If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
                m_InitializingDefInstance = True
                m_vb6FormDefInstance = New Form1()
                m_InitializingDefInstance = False
            End If
            DefInstance = m_vb6FormDefInstance
        End Get
        Set(ByVal value As Form1)
            m_vb6FormDefInstance = value
        End Set
    End Property

I don't know enough about the VB.Net IDE to know what is going on. I do know that just changing every instance of "Form1" to "frmMain" does not seem to work.

Greg
 
Doh!

Ok, I see what was happening now. I was clicking on the file object in the solution explorer and pressing F4 to change the object name, which would change the name of the file. This was deceiving because the form designer was also open. What I needed to do was open the form designer - click on it - and then press F4 to bring up the properties of the designer.

That still doesn't explain why changing the Me.Name = "Form1" in the designer didn't work. I read an article some where on-line that said that would work. Also, for some reason this form was "Friend Class" instead of "Public Class". That one is still a mystery.
 
Me.Name = "Form1"
It seems to me you are here referring to Designer generated code (*), something you should never edit manually.

(* meaning the .Designer.vb files or "generated code - do not modify" regions)
 
Perhaps you're right, but when you're trying to find solutions you sometimes try anything to see if it will work. Like I said, I read an article on-line that discussed the designer generated code.
 
Back
Top