473,396 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Derive From CancelEventArgs

Hello All,

I am looking for an example showing a custom EventArgs
class that derives from CancelEventsArgs, and a form or
control using that class in a custom event.

The simpler, the better, but I'll take anything...

Thanks,
G72
Nov 16 '05 #1
4 4519
hi

what you want to do?
simple derive it and add your functionality. be aware that the controls will
still use CancelEventsArgs , so you will need to derive the controls you
want to fire the event with the new type.

Also I suggest you to always check the eventargs type in the handler before
doing the cast.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Gates72" <an*******@discussions.microsoft.com> wrote in message
news:19****************************@phx.gbl...
Hello All,

I am looking for an example showing a custom EventArgs
class that derives from CancelEventsArgs, and a form or
control using that class in a custom event.

The simpler, the better, but I'll take anything...

Thanks,
G72

Nov 16 '05 #2
Hello Gates72,

As desired a simple example.

HTH, Günther

On Fri, 25 Feb 2005 05:45:41 -0800, "Gates72"
<an*******@discussions.microsoft.com> wrote:
Hello All,

I am looking for an example showing a custom EventArgs
class that derives from CancelEventsArgs, and a form or
control using that class in a custom event.

The simpler, the better, but I'll take anything...

Thanks,
G72


Nov 16 '05 #3
public class MyCancelEventsArgs : CancelEventsArgs
{
}

And now?
"Gates72" <an*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:19****************************@phx.gbl...
Hello All,

I am looking for an example showing a custom EventArgs
class that derives from CancelEventsArgs, and a form or
control using that class in a custom event.

The simpler, the better, but I'll take anything...

Thanks,
G72

Nov 16 '05 #4
Hi Gates72,

Here is a simple Windows-Forms example. Please copy and paste.

HTH, günther

begin....

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

namespace WindowsApplication1
{
#region form1

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.ComponentModel.Container components =
null;
public event CancelEventHandler UseLessEventHandler;

public Form1()
{
InitializeComponent();
this.UseLessEventHandler += new
CancelEventHandler(Form1_UseLessEventHandler);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
this.button1 = new
System.Windows.Forms.Button();
this.label1 = new
System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new
System.Drawing.Point(108, 74);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new
System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new
System.Drawing.Point(102, 110);
this.label1.Name = "label1";
this.label1.TabIndex = 1;
this.label1.Text = "label1";
this.label1.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter;
//
// Form1
//
this.AutoScaleBaseSize = new
System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(328,
197);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion
#region MyCancelEventArgs
public class MyCancelEventArgs : CancelEventArgs
{
private object tag = null;
public MyCancelEventArgs()
{
}
public object Tag
{
get
{
return this.tag;
}
set
{
this.tag = value;
}
}
}
#endregion

private void Form1_UseLessEventHandler(object sender,
CancelEventArgs e)
{
if( MessageBox.Show( this, "Do you want to
cancel this?", "?", MessageBoxButtons.YesNo ) == DialogResult.Yes )
{
e.Cancel = true;
}
}
private void button1_Click(object sender,
System.EventArgs e)
{
MyCancelEventArgs ce = null;
if( this.UseLessEventHandler != null )
{
ce = new MyCancelEventArgs();
ce.Tag = this; // or whatever;
this.UseLessEventHandler( this, ce );

if( ce.Cancel )
{
this.label1.Text = "You
cancelled!";
}
else
{
this.label1.Text =
"braveheart";
}
}
else
{
this.label1.Text = "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 MyCancelEventsArgs : CancelEventsArgs
{
}

And now?
"Gates72" <an*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:19****************************@phx.gbl...
Hello All,

I am looking for an example showing a custom EventArgs
class that derives from CancelEventsArgs, and a form or
control using that class in a custom event.

The simpler, the better, but I'll take anything...

Thanks,
G72


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Ron Garret | last post by:
Why doesn't this work? >>> from weakref import ref >>> class C(str): pass .... >>> ref(C()) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: cannot create weak...
3
by: Marcin Kowalewski | last post by:
Hi I've got a stupid problem with code below : using System; using System.Drawing; .... public class CsrcImage :Image { public CsrcImage() { //
4
by: Henke | last post by:
Hi! I have a abstract base class that derives from System.Web.UI.Page. In this class I have some abstract methods. My other web pages should derive from this class and implement the abstract...
5
by: Mike Labosh | last post by:
In VB 6, the Form_QueryUnload event had an UnloadMode parameter that let me find out *why* a form is unloading, and then conditionally cancel the event. In VB.NET, the Closing event passes a...
3
by: gyan | last post by:
Please go though following program: #include <iostream.h> class base { public: int basepublic; protected: int baseprotected; };
3
by: hufaunder | last post by:
Imagine you have a charting library that can draw lines, bars, floating bars, bands, etc. Lines and bars need only one input. Floating bars and bands need two inputs. There are two approaches: ...
4
by: Peted | last post by:
Hello this is the click event method of a radio button private void radioButton1_Click(object sender, EventArgs e) { }
2
by: Andrus | last post by:
I try to compile myGeneration source code using Visual C# Express 2005 Express. File starts with using System; using System.Xml; using System.Data; using System.Data.OleDb;
2
by: Markus Dehmann | last post by:
I want to derive from std::set, like shown below. But when I try to declare an iterator over the contained elements I get an error, see the twp uncommented lines: #include <set> template<class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.