473,387 Members | 1,536 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,387 software developers and data experts.

Event Problem

I want use a different signature for a base class event and also override the
On... protected method. It's not working. What am I doing wrong? Here's
the code.

public partial class UCBase : UserControl
{
public event EventHandler IWasClicked;

public UCBase()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.OnIWasClicked(EventArgs.Empty);
}

protected virtual void OnIWasClicked(EventArgs e)
{
if (this.IWasClicked != null)
this.IWasClicked(this, e);
}
}
public partial class UCSpecial : UCBase
{

public new event CancelEventHandler IWasClicked;

public UCSpecial()
{
InitializeComponent();
}

protected override void OnIWasClicked(EventArgs e)
{
this.OnIWasClicked(CancelEventArgs.Empty);
}

protected virtual void OnIWasClicked(CancelEventArgs e)
{
MessageBox.Show("UCSpecial before raising the event.");

if (this.IWasClicked != null)
this.IWasClicked(this, e);
}
}

--
Willy
Mar 2 '06 #1
3 1177

Willy_At_Work wrote:
I want use a different signature for a base class event and also override the
On... protected method. It's not working. What am I doing wrong? Here's
the code. protected override void OnIWasClicked(EventArgs e)
{
this.OnIWasClicked(CancelEventArgs.Empty); // here
}

protected virtual void OnIWasClicked(CancelEventArgs e)
{
MessageBox.Show("UCSpecial before raising the event.");

if (this.IWasClicked != null)
this.IWasClicked(this, e);
}


The problem is that CancelEventArgs.Empty is an EventArgs, not a
CancelEventArgs. So the line I have commented 'here' just calls itself
until the stack overflows.

--
Larry Lard
Replies to group please

Mar 2 '06 #2

Larry Lard wrote:
Willy_At_Work wrote:
I want use a different signature for a base class event and also override the
On... protected method. It's not working. What am I doing wrong? Here's
the code.

protected override void OnIWasClicked(EventArgs e)
{
this.OnIWasClicked(CancelEventArgs.Empty); // here
}

protected virtual void OnIWasClicked(CancelEventArgs e)
{
MessageBox.Show("UCSpecial before raising the event.");

if (this.IWasClicked != null)
this.IWasClicked(this, e);
}


The problem is that CancelEventArgs.Empty is an EventArgs, not a
CancelEventArgs. So the line I have commented 'here' just calls itself
until the stack overflows.


I should add, the fix is to change the commented line to

this.OnIWasClicked(new CancelEventArgs());

--
Larry Lard
Replies to group please

Mar 2 '06 #3
That's interesting... An empty type is of a different type.

Thanks for the help.
--
Willy
"Larry Lard" wrote:

Larry Lard wrote:
Willy_At_Work wrote:
I want use a different signature for a base class event and also override the
On... protected method. It's not working. What am I doing wrong? Here's
the code.

protected override void OnIWasClicked(EventArgs e)
{
this.OnIWasClicked(CancelEventArgs.Empty); // here
}

protected virtual void OnIWasClicked(CancelEventArgs e)
{
MessageBox.Show("UCSpecial before raising the event.");

if (this.IWasClicked != null)
this.IWasClicked(this, e);
}


The problem is that CancelEventArgs.Empty is an EventArgs, not a
CancelEventArgs. So the line I have commented 'here' just calls itself
until the stack overflows.


I should add, the fix is to change the commented line to

this.OnIWasClicked(new CancelEventArgs());

--
Larry Lard
Replies to group please

Mar 2 '06 #4

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

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
6
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new...
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
6
by: hemant.singh | last post by:
Hi all, I am trying to get a way by which I'll know exactly when user goes out of my site by clicking on close button in browser, So that w/e user click close button in browser, I can send a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.