private void MainForm_Activate(object sender, EventArgs e) { // load data from database Listdata = Database.LoadData(); // update UI controls dataGridView1.DataSource = data; label1.Text = $"Loaded {data.Count} items."; }
private void MainForm_Activate(object sender, EventArgs e) { // check for running instance of application Process[] processes = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName); if (processes.Length > 1) { // another instance is running, close current instance this.Close(); } }Both of these examples use the `System.Windows.Forms` library, which provides the `MainForm` class and the `Activate` event.