Event
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace eventbuttonexample
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void Form1_Load(object
sender, EventArgs e)
{
Button
b1 = new Button();
this.Controls.Add(b1);
b1.Location = new Point(50, 50);
b1.Size = new
Size(100, 50);
b1.BackColor = System.Drawing.Color.Aqua;
b1.Text = "tanuj";
b1.Click += new EventHandler(a);
}
private
void a(Object sender, EventArgs
e)
{
MessageBox
.Show ("button is clicked");} }}
Adding a textbox on
run time:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace eventtextboxexample
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void Form1_Load(object
sender, EventArgs e)
{
TextBox
tb = new TextBox();
this.Controls.Add(tb);
tb.Location = new Point(50, 50);
tb.TextChanged +=new EventHandler(a);
tb.BackColor = System.Drawing.Color.Aqua;
}
private
void a(Object
sender, EventArgs e) {
MessageBox.Show("text is changed");
}
}
}
Posted By:Tanuj Kumar
Comments
Post a Comment