Wednesday, April 8, 2009

.NET Windows Form Activated event - C#

Form2.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form2 : Form
{
Form1 oForm1;
public Form2()
{
InitializeComponent();
oForm1 = new Form1();
}

private void button1_Click(object sender, EventArgs e)
{
oForm1.Show();
oForm1.Activate();
}
}
}

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
static int noOfActivation;
public Form1()
{
InitializeComponent();
}
private void Form1_Activated(object sender, System.EventArgs e)
{
noOfActivation = noOfActivation +1;
label1.Text = "Activated: " + noOfActivation;
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}


Output

Followers

About Me

Happily married, live in Dallas with his wife and daughter. Working as a Product Manager.