Howto determine the startup form of a project?

I'm trying to figure out which form is the startup form for a WinForms project. Ive looked for some property in the project or the VB file itself and neither one seems to know the answer. More specifically, I'm looking at the Properties collection of the project and the projectitems objects using the DTE.

Obviously I'm missing it here. Where can I look to find this information

Thanks
Bill



Answer this question

Howto determine the startup form of a project?

  • Togo

    This is a little outside areas with which I'm familiar, but WindowsFormsApplicationBase.MainForm Property looks promising. It's in the Midrosoft.VisualBasic.ApplicationServices namespace of the .NET Framework.
  • dpollo

    You just click on 'Project' in the menu and then select the bottom menu option.
    It should be 'projectname Properties'.
    Then under 'Common Properties' select 'General' in the dialog box that pops up.
    The fourth item under the 'Application' group tells you the startup object of your
    project.

    If you're after how to find this during run-time I don't know.


  • Raymundo Chapa94595

    Sorry, I guess I wasnt clear on this. I'm trying to do this in code using the DTE to examine the Project and ProjectItem classes representing the project loaded into visual studio 2005.

    :)

    Bill

  • IraD

    Bill,

    Check Project's Properties collection. If I recall one of the properties exposes startup form. FYI, collection items can be retrieved by name.

  • Crumbs

    Would this work

    Sub Macro2()

    Dim objProject As Project = DTE.Solution.Projects.Item(1)

    For Each objPI As ProjectItem In objProject.ProjectItems

    If objPI.Name = "My Project" Then

    For Each objPI2 As ProjectItem In objPI.ProjectItems

    If objPI2.Name.ToLower = "application.myapp" Then

    Dim objXDoc As New XmlDocument

    objXDoc.Load(objPI2.FileNames(0))

    MsgBox(objXDoc.GetElementsByTagName("MainForm").Item(0).InnerText)

    End If

    Next

    End If

    Next

    End Sub



  • Simn

    This is way too difficult and not very reliable Sad. In VS2003, I can always use the startupObject property but now VB.Net changes this and the worse thing is this property is dynamic on the Application Project Designer (determined by the Enabled application framework checkbox). 

    I was looking at the VBProjectProperties3 which has a MyApplication property but it is of type object so I can't tell if it is useful or not. Any ideas Is there any better way to look up the start up form/object

  • Trevor L.

    There is a "StartupObject" property, but its value is useless. Its value is "TestRefresh.My.MyApplication" and the generated code-behind for the project in the Application.Designer.VB file has

    <Global.System.Diagnostics.DebuggerStepThroughAttribute()>
    Protected Overrides Sub OnCreateMainForm()
    Me.MainForm = Global.TestRefresh.Form1
    End Sub

    which is where the form is actually created.
     
    Ive come to the conclusion that I will have to use the CodeModel to get into this function and parse it out, but the fact remains that this is annoying at best and impossible for people without a good deal of experience.


  • Howto determine the startup form of a project?