473,698 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Derive From CancelEventArgs

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
Nov 16 '05 #1
4 4539
hi

what you want to do?
simple derive it and add your functionality. be aware that the controls will
still use CancelEventsArg s , 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*******@disc ussions.microso ft.com> wrote in message
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

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*******@disc ussions.microso ft.com> wrote:
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


Nov 16 '05 #3
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

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.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


Nov 16 '05 #5

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

Similar topics

12
2722
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 reference to 'C' object >>>
3
6100
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
1317
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 methods. When I try to display the derived web page in the designer I get an error: " The file could not be loaded into the Web Forms designer. Please correct the following error and then try loading it again:
5
3014
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 CancelEventArgs that lets me cancel the Close() operation, but is there still any way to find out *why* a form is closing? This app as a form that needs to be loaded at startup, closed only at shutdown, and then Show() / Hide() for the user. If...
3
1652
by: gyan | last post by:
Please go though following program: #include <iostream.h> class base { public: int basepublic; protected: int baseprotected; };
3
3038
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: 1) One enum with all 4 types (bars, band, etc). One chart class that accepts up to 2 arrays of values. If the user choses a band but there is only one input array throw an exception. If the user passes two input arrays with different lengths throw...
4
9595
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
5313
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
2790
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 T> class MySet : public std::set<T>{ public: MySet() : std::set<T>() {} void foo(){
0
8675
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8862
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7729
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.