Multiple Forms

I am trying to use multiple forms in my c# app. What i would like to do is open the program with one form, and if a user lets say clicks on a button or something, then a different form will open up. how would this be done?

Comments

  • Not sure if you wanted it to do anything else but this is the basic way to do it:

    private void button_Click(object sender, System.EventArgs e)
    {
    Form Name = new Form2();
    Name.Show();
    }
  • : Not sure if you wanted it to do anything else but this is the basic way to do it:
    :
    : private void button_Click(object sender, System.EventArgs e)
    : {
    : Form Name = new Form2();
    : Name.Show();
    : }
    :

    hrmm, so if i already had the second form made, would it be something like this??

    private void button_Click(object sender, System.EventArgs e)
    {
    Form Name = frmAlreadyMadeForm();
    Name.Show();
    }
  • : hrmm, so if i already had the second form made, would it be something like this??
    :
    : private void button_Click(object sender, System.EventArgs e)
    : {
    : Form Name = frmAlreadyMadeForm();
    : Name.Show();
    : }
    :
    You still need the "new" in the first line
    private void button_Click(object sender, System.EventArgs e)
    {
    Form Name = [b]new[/b] frmAlreadyMadeForm();
    Name.Show();
    }
  • : : hrmm, so if i already had the second form made, would it be something like this??
    : :
    : : private void button_Click(object sender, System.EventArgs e)
    : : {
    : : Form Name = frmAlreadyMadeForm();
    : : Name.Show();
    : : }
    : :
    : You still need the "new" in the first line
    : private void button_Click(object sender, System.EventArgs e)
    : {
    : Form Name = [b]new[/b] frmAlreadyMadeForm();
    : Name.Show();
    : }
    :


    Here is my code:

    Private void btnNewGame_Click (object sendiner, System.EventArgs e)
    {
    Form NewGameOptions= new frmNewGameOptions();
    NewGameOptions.show();
    }


    and i get the follwing errors:

    End of Statement Expected-dealing with first bracket
    Syntax Error-dealing with first bracket
    Declaration Expected-Form NewGameOptions= new frmNewGameOptions();
    Declaration Expected-NewGameOptions.show();
    Syntax Error-dealing with the last bracket


  • : : : hrmm, so if i already had the second form made, would it be something like this??
    : : :
    : : : private void button_Click(object sender, System.EventArgs e)
    : : : {
    : : : Form Name = frmAlreadyMadeForm();
    : : : Name.Show();
    : : : }
    : : :
    : : You still need the "new" in the first line
    : : private void button_Click(object sender, System.EventArgs e)
    : : {
    : : Form Name = [b]new[/b] frmAlreadyMadeForm();
    : : Name.Show();
    : : }
    : :
    :
    :
    : Here is my code:
    :
    : Private void btnNewGame_Click (object sendiner, System.EventArgs e)
    : {
    : Form NewGameOptions= new frmNewGameOptions();
    : NewGameOptions.show();
    : }
    :
    :
    : and i get the follwing errors:
    :
    : End of Statement Expected-dealing with first bracket
    : Syntax Error-dealing with first bracket
    : Declaration Expected-Form NewGameOptions= new frmNewGameOptions();
    : Declaration Expected-NewGameOptions.show();
    : Syntax Error-dealing with the last bracket
    :
    You made some typos:
    [code]
    [red]p[/red]rivate void btnNewGame_Click (object [red]sender[/red], System.EventArgs e)
    {
    Form NewGameOptions= new frmNewGameOptions();
    [red]/*Better to use the correct derived type instead of the line above:
    frmNewGameOptions NewGameOptions= new frmNewGameOptions();
    [/red]*/
    NewGameOptions.[red]S[/red]how();
    }
    [/code]

    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl


  • : : : : hrmm, so if i already had the second form made, would it be something like this??
    : : : :
    : : : : private void button_Click(object sender, System.EventArgs e)
    : : : : {
    : : : : Form Name = frmAlreadyMadeForm();
    : : : : Name.Show();
    : : : : }
    : : : :
    : : : You still need the "new" in the first line
    : : : private void button_Click(object sender, System.EventArgs e)
    : : : {
    : : : Form Name = [b]new[/b] frmAlreadyMadeForm();
    : : : Name.Show();
    : : : }
    : : :
    : :
    : :
    : : Here is my code:
    : :
    : : Private void btnNewGame_Click (object sendiner, System.EventArgs e)
    : : {
    : : Form NewGameOptions= new frmNewGameOptions();
    : : NewGameOptions.show();
    : : }
    : :
    : :
    : : and i get the follwing errors:
    : :
    : : End of Statement Expected-dealing with first bracket
    : : Syntax Error-dealing with first bracket
    : : Declaration Expected-Form NewGameOptions= new frmNewGameOptions();
    : : Declaration Expected-NewGameOptions.show();
    : : Syntax Error-dealing with the last bracket
    : :
    : You made some typos:
    : [code]
    : [red]p[/red]rivate void btnNewGame_Click (object [red]sender[/red], System.EventArgs e)
    : {
    : Form NewGameOptions= new frmNewGameOptions();
    : [red]/*Better to use the correct derived type instead of the line above:
    : frmNewGameOptions NewGameOptions= new frmNewGameOptions();
    : [/red]*/
    : NewGameOptions.[red]S[/red]how();
    : }
    : [/code]
    :
    : Greets,
    : Eric Goldstein
    : http://www.gvh-maatwerk.nl
    :
    :
    :



    even with fixing the the errors you mentioned, i am still getting the same errors on the same lines.
  • Hi,

    Can you try this one.

    frmNewGameOptions NewGameOptions= new frmNewGameOptions();
    NewGameOptions.show();




    : : : : : hrmm, so if i already had the second form made, would it be something like this??
    : : : : :
    : : : : : private void button_Click(object sender, System.EventArgs e)
    : : : : : {
    : : : : : Form Name = frmAlreadyMadeForm();
    : : : : : Name.Show();
    : : : : : }
    : : : : :
    : : : : You still need the "new" in the first line
    : : : : private void button_Click(object sender, System.EventArgs e)
    : : : : {
    : : : : Form Name = [b]new[/b] frmAlreadyMadeForm();
    : : : : Name.Show();
    : : : : }
    : : : :
    : : :
    : : :
    : : : Here is my code:
    : : :
    : : : Private void btnNewGame_Click (object sendiner, System.EventArgs e)
    : : : {
    : : : Form NewGameOptions= new frmNewGameOptions();
    : : : NewGameOptions.show();
    : : : }
    : : :
    : : :
    : : : and i get the follwing errors:
    : : :
    : : : End of Statement Expected-dealing with first bracket
    : : : Syntax Error-dealing with first bracket
    : : : Declaration Expected-Form NewGameOptions= new frmNewGameOptions();
    : : : Declaration Expected-NewGameOptions.show();
    : : : Syntax Error-dealing with the last bracket
    : : :
    : : You made some typos:
    : : [code]
    : : [red]p[/red]rivate void btnNewGame_Click (object [red]sender[/red], System.EventArgs e)
    : : {
    : : Form NewGameOptions= new frmNewGameOptions();
    : : [red]/*Better to use the correct derived type instead of the line above:
    : : frmNewGameOptions NewGameOptions= new frmNewGameOptions();
    : : [/red]*/
    : : NewGameOptions.[red]S[/red]how();
    : : }
    : : [/code]
    : :
    : : Greets,
    : : Eric Goldstein
    : : http://www.gvh-maatwerk.nl
    : :
    : :
    : :
    :
    :
    :
    : even with fixing the the errors you mentioned, i am still getting the same errors on the same lines.
    :



  • : : : : : hrmm, so if i already had the second form made, would it be something like this??
    : : : : :
    : : : : : private void button_Click(object sender, System.EventArgs e)
    : : : : : {
    : : : : : Form Name = frmAlreadyMadeForm();
    : : : : : Name.Show();
    : : : : : }
    : : : : :
    : : : : You still need the "new" in the first line
    : : : : private void button_Click(object sender, System.EventArgs e)
    : : : : {
    : : : : Form Name = [b]new[/b] frmAlreadyMadeForm();
    : : : : Name.Show();
    : : : : }
    : : : :
    : : :
    : : :
    : : : Here is my code:
    : : :
    : : : Private void btnNewGame_Click (object sendiner, System.EventArgs e)
    : : : {
    : : : Form NewGameOptions= new frmNewGameOptions();
    : : : NewGameOptions.show();
    : : : }
    : : :
    : : :
    : : : and i get the follwing errors:
    : : :
    : : : End of Statement Expected-dealing with first bracket
    : : : Syntax Error-dealing with first bracket
    : : : Declaration Expected-Form NewGameOptions= new frmNewGameOptions();
    : : : Declaration Expected-NewGameOptions.show();
    : : : Syntax Error-dealing with the last bracket
    : : :
    : : You made some typos:
    : : [code]
    : : [red]p[/red]rivate void btnNewGame_Click (object [red]sender[/red], System.EventArgs e)
    : : {
    : : Form NewGameOptions= new frmNewGameOptions();
    : : [red]/*Better to use the correct derived type instead of the line above:
    : : frmNewGameOptions NewGameOptions= new frmNewGameOptions();
    : : [/red]*/
    : : NewGameOptions.[red]S[/red]how();
    : : }
    : : [/code]
    : :
    : : Greets,
    : : Eric Goldstein
    : : http://www.gvh-maatwerk.nl
    : :
    : :
    : :
    :
    :
    :
    : even with fixing the the errors you mentioned, i am still getting the same errors on the same lines.

    Then there is some misaligning-bracket problem elsewhere in the file. Post the whole code (and please use code-tags).


    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl


  • here is the full code for my main form. please note that im floating around on the USS Comstock, out near San Diego, using a goverment laptop for the internet, and my personal laptop for programming. This being said, copying code around can be a little pain...

    Public Class frmMainMenu
    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 btnNewGame As System.Windows.Forms.Button
    Friend WithEvents btnLoadGame As System.Windows.Forms.Button
    Friend WithEvents btnQuit As System.Windows.Forms.Button
    Private Sub InitializeComponent()
    Me.btnNewGame = New System.Windows.Forms.Button
    Me.btnLoadGame = New System.Windows.Forms.Button
    Me.btnQuit = New System.Windows.Forms.Button
    Me.SuspendLayout()
    '
    'btnNewGame
    '
    Me.btnNewGame.Location = New System.Drawing.Point(8, 8)
    Me.btnNewGame.Name = "btnNewGame"
    Me.btnNewGame.Size = New System.Drawing.Size(176, 24)
    Me.btnNewGame.TabIndex = 0
    Me.btnNewGame.Text = "New Game"
    '
    'btnLoadGame
    '
    Me.btnLoadGame.Location = New System.Drawing.Point(8, 32)
    Me.btnLoadGame.Name = "btnLoadGame"
    Me.btnLoadGame.Size = New System.Drawing.Size(176, 24)
    Me.btnLoadGame.TabIndex = 1
    Me.btnLoadGame.Text = "Load Game"
    '
    'btnQuit
    '
    Me.btnQuit.DialogResult = System.Windows.Forms.DialogResult.Cancel
    Me.btnQuit.Location = New System.Drawing.Point(8, 56)
    Me.btnQuit.Name = "btnQuit"
    Me.btnQuit.Size = New System.Drawing.Size(176, 24)
    Me.btnQuit.TabIndex = 2
    Me.btnQuit.Text = "Quit"
    '
    'frmMainMenu
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(192, 86)
    Me.ControlBox = False
    Me.Controls.Add(Me.btnQuit)
    Me.Controls.Add(Me.btnLoadGame)
    Me.Controls.Add(Me.btnNewGame)
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.Name = "frmMainMenu"
    Me.Text = "World War Three"
    Me.ResumeLayout(False)

    End Sub

    #End Region

    Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
    End Sub

    private void btnNewGame_Click(object sender, System.EventArgs e)
    {
    Form NewGameOptions=new frmNewGameOptions();
    NewGameOptions.Show();
    }
    End Class
  • What's that?
    You are mixing VB.Net and C# code in the same source!
    No wonder it doesn't compile!

    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories