Files
VS_HCI/Workshop2/Form1.cs
2024-01-19 14:01:14 +00:00

34 lines
899 B
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Workshop2
{
public partial class Form1 : Form
{
//Form2 f2 = new Form2();
public Form2 f2;
public Form1()
{
InitializeComponent();
}
private void showForm2button_Click(object sender, EventArgs e)
{
if (f2 == null)
{
f2 = new Form2();// you need to set the textbox in form2 to public
f2.textBox1.Text = "Initially Set from form1";// need to ensure if the form is closed it is dereferenced
f2.FormClosed += delegate {
f2 = null;
};
}
f2.Show();
}
}
}