Hi Gates72,
Here is a simple Windows-Forms example. Please copy and paste.
HTH, günther
begin....
using System;
using System.Componen tModel;
using System.Drawing;
using System.Collecti ons;
using System.Windows. Forms;
using System.Data;
namespace WindowsApplicat ion1
{
#region form1
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Button button1;
private System.Windows. Forms.Label label1;
private System.Componen tModel.Containe r components =
null;
public event CancelEventHand ler UseLessEventHan dler;
public Form1()
{
InitializeCompo nent();
this.UseLessEve ntHandler += new
CancelEventHand ler(Form1_UseLe ssEventHandler) ;
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.button1 = new
System.Windows. Forms.Button();
this.label1 = new
System.Windows. Forms.Label();
this.SuspendLay out();
//
// button1
//
this.button1.Lo cation = new
System.Drawing. Point(108, 74);
this.button1.Na me = "button1";
this.button1.Ta bIndex = 0;
this.button1.Te xt = "button1";
this.button1.Cl ick += new
System.EventHan dler(this.butto n1_Click);
//
// label1
//
this.label1.Loc ation = new
System.Drawing. Point(102, 110);
this.label1.Nam e = "label1";
this.label1.Tab Index = 1;
this.label1.Tex t = "label1";
this.label1.Tex tAlign =
System.Drawing. ContentAlignmen t.MiddleCenter;
//
// Form1
//
this.AutoScaleB aseSize = new
System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(328,
197);
this.Controls.A dd(this.label1) ;
this.Controls.A dd(this.button1 );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);
}
#endregion
#region MyCancelEventAr gs
public class MyCancelEventAr gs : CancelEventArgs
{
private object tag = null;
public MyCancelEventAr gs()
{
}
public object Tag
{
get
{
return this.tag;
}
set
{
this.tag = value;
}
}
}
#endregion
private void Form1_UseLessEv entHandler(obje ct sender,
CancelEventArgs e)
{
if( MessageBox.Show ( this, "Do you want to
cancel this?", "?", MessageBoxButto ns.YesNo ) == DialogResult.Ye s )
{
e.Cancel = true;
}
}
private void button1_Click(o bject sender,
System.EventArg s e)
{
MyCancelEventAr gs ce = null;
if( this.UseLessEve ntHandler != null )
{
ce = new MyCancelEventAr gs();
ce.Tag = this; // or whatever;
this.UseLessEve ntHandler( this, ce );
if( ce.Cancel )
{
this.label1.Tex t = "You
cancelled!";
}
else
{
this.label1.Tex t =
"braveheart ";
}
}
else
{
this.label1.Tex t = "You just Clicked -
nothing more!";
}
}
#endregion
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
}
}
end ....
On Fri, 25 Feb 2005 17:34:57 +0100, "cody" <de********@gmx .de> wrote:
public class MyCancelEventsA rgs : CancelEventsArg s
{
}
And now?
"Gates72" <an*******@disc ussions.microso ft.com> schrieb im Newsbeitrag
news:19******* *************** ******@phx.gbl. .. Hello All,
I am looking for an example showing a custom EventArgs
class that derives from CancelEventsArg s, and a form or
control using that class in a custom event.
The simpler, the better, but I'll take anything...
Thanks,
G72