RSS

Simple Example for event handling in C#

To place a singe button(Button1),textbox(txtViewer) in the Form and create teh new user defind method called OnClick() and wireup the event using the bellow code part

//The Default Form1() initializer Method
public Form1()
{
InitializeComponent();
button1.Click += new EventHandler(OnClick);// Onclick Based
this.Resize+=new EventHandler(this.ResizeForm); //While Form is Resized
}

// User defind method wireupped with Button1 Click
public void OnClick(object sender, EventArgs e)
{
this.txtViewer.Text = "This is test for Event";
}

//User defind method wired with form resize
private void ResizeForm(object sender, EventArgs e)
{
MessageBox.Show("Oops! Form Resized");
}

0 comments:

Post a Comment