|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PassBetweenForms
{
public partial class frmID : Form
{
// add a delegate
public delegate void IdentityUpdateHandler(object sender, IdentityUpdateEventArgs e);
// add an event of the delegate type
public event IdentityUpdateHandler IdentityUpdated;
// default constructor
public frmID()
{
InitializeComponent();
}
// close the form without raising the event
private void btnCancel_Click(object sender, EventArgs e)
{
this.Dispose();
}
// raise the event
private void btnOkay_Click(object sender, EventArgs e)
{
// this button click event handler will raise the
// event which can then intercepted by any listeners
// read the textboxes and set the member variables
string sNewFirst = txtFirstName.Text;
string sNewMiddle = txtMiddleName.Text;
string sNewLast = txtLastName.Text;
// instance the event args and pass it each value
IdentityUpdateEventArgs args = new IdentityUpdateEventArgs(sNewFirst,
sNewMiddle, sNewLast);
// raise the event with the updated arguments
IdentityUpdated(this, args);
this.Dispose();
}
}
public class IdentityUpdateEventArgs : System.EventArgs
{
// add local member variable to hold text
private string mFirstName;
private string mMiddleName;
private string mLastName;
// class constructor
public IdentityUpdateEventArgs(string sFirstName, string sMiddleName, string sLastName)
{
this.mFirstName = sFirstName;
this.mMiddleName = sMiddleName;
this.mLastName = sLastName;
}
// Properties - Accessible by the listener
public string FirstName
{
get
{
return mFirstName;
}
}
public string MiddleName
{
get
{
return mMiddleName;
}
}
public string LastName
{
get
{
return mLastName;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.