• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Setting startup form

I know this is a really bad question.  I'm asking it anyway because I'm just not finding the exact answer I want.

I have about 12 forms created now.  I want to set one as the starting form and then move between forms by loading one and unloading the other.  How do I set the form to start with?

JP
0
gleznov
Asked:
gleznov
  • 6
  • 5
  • 2
2 Solutions
 
tzxie2000Commented:
select Project->yourporject property
set start object to your startup form
0
 
gleznovAuthor Commented:
Thanks - one more question for ya, I'll up the points  -  how do I now switch between forms?  In VB6 it was Unload Me, then Load frm  or something similar - how do I open one form?  Unload Me still works, but I don't see how to open the next form.  Thanks!

JP
0
 
planoczCommented:
add this to your forms, It make a better entrance point for your forms

    '/ <summary>
    '/ The main entry point for the application.
    '/ </summary>
    <STAThread()> Public Shared Sub Main()
        Application.Run(New frmForm)             '<---- name of your form
    End Sub
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
gleznovAuthor Commented:
or pardon, Me.Close() is what closes forms now.  
0
 
planoczCommented:
to jump to the next form.....

            Dim objForm As New frmView   '<---- name of form
            objForm.ShowDialog()
0
 
tzxie2000Commented:
in form1
some switch button write
me.hide()
form2.show()

in form2
some switch button write
me.hide()
form1.show()

create form1,form2 as a global variant
0
 
planoczCommented:
Example: If you had a Exit or Cancel Button....

  Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
0
 
gleznovAuthor Commented:
OK so far 50 points for each of you, I'm upping it one more time to ask this:

How can I close one form and open the next?  I can either:

close the form

or

open the new one

But I can't seem to do both...

Here's the code - there's a timer, after 2 seconds, it does this:

 Private Sub Timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        Dim objForm As New frmLogin   '<---- name of form
        Me.Close()
        objForm.ShowDialog()

    End Sub

This only closes the form and it's over.

I've also tried:

        Dim objForm As New frmLogin   '<---- name of form
        objForm.ShowDialog()
        Me.Close()

And this doesn't close the form, but every 2 seconds it opens a new instance of frmLogin

JP
0
 
planoczCommented:
'FORM 1

    '/ <summary>
    '/ The main entry point for the application.
    '/ </summary>
    <STAThread()> Public Shared Sub Main()
        Application.Run(New Form1)            
    End Sub

  Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    Dim objForm As New frmForm2   '<---- name of form
            objForm.ShowDialog()
   End Sub


'FORM 2

   '/ <summary>
    '/ The main entry point for the application.
    '/ </summary>
    <STAThread()> Public Shared Sub Main()
        Application.Run(New Form2)            
    End Sub

  Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    Dim objForm As New frmForm3   '<---- name of form
            objForm.ShowDialog()
   End Sub

0
 
gleznovAuthor Commented:
That code still only closes Form 1, but doesn't open form 2

JP
0
 
gleznovAuthor Commented:
Wait, do I need to add that <STAThread> stuff?

What's that do?

JP
0
 
planoczCommented:
This is a sample app....

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnExit = New System.Windows.Forms.Button
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.MenuItem3 = New System.Windows.Forms.MenuItem
        Me.SuspendLayout()
        '
        'btnExit
        '
        Me.btnExit.Location = New System.Drawing.Point(192, 224)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(60, 24)
        Me.btnExit.TabIndex = 0
        Me.btnExit.Text = "Next"
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3})
        Me.MenuItem1.Text = "Forms"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 0
        Me.MenuItem2.Text = "Forms2"
        '
        'MenuItem3
        '
        Me.MenuItem3.Index = 1
        Me.MenuItem3.Text = "Forms3"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.Add(Me.btnExit)
        Me.Menu = Me.MainMenu1
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region
    '/ <summary>
    '/ The main entry point for the application.
    '/ </summary>
    <STAThread()> Public Shared Sub Main()
        Application.Run(New Form1)
    End Sub

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Dim objForm As New frmCase   '<---- name of form
        objForm.ShowDialog()
        Me.Close()
    End Sub

    Private Sub Menu_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem2.Click, MenuItem3.Click
        Select Case sender.Text
            Case "Forms2"
                Dim objForm As New Form2   '<---- name of form
                objForm.ShowDialog()
            Case "Forms3"
                Dim objForm As New Form3   '<---- name of form
                objForm.ShowDialog()
        End Select

    End Sub

End Class
0
 
planoczCommented:
if you want to see each form together then change this code piece per form....
from the above code

before..
  objForm.ShowDialog()
After..
  objForm.Show()
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now