Skip to content

Latest commit

 

History

History
40 lines (35 loc) · 730 Bytes

form.md

File metadata and controls

40 lines (35 loc) · 730 Bytes

Forms

Passing data between forms

I like to pass reference types on the initializer of new forms. This lets them share variables.

Create/Launch a new Form

Form2 f2 = new Form2();
f2.Show();

Accessing form data

using (FormSoundCard frm = new FormSoundCard())
{
    frm.ShowDialog();
    Console.WriteLine(frm.deviceNumber);
}

Switch to another form

private void button2_Click(object sender, EventArgs e)
{
    Form2 f2 = new Form2();
    f2.Show();
    this.Hide();
}

Launch another form by default

Edit Program.cs

static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form2());
}