473,855 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass more than two parameters in the event handler

Can anyone suggest me to pass more parameters other than two parameter for
events like the following?

Event:
Onbutton_click( object sender, EventArgs e)"

Event handler:
button.Click += new EventHandler(On button_click);

I want to pass more information related that event. & want to use that
information in the event.
Jul 17 '08
24 55280
On Thu, 17 Jul 2008 01:38:01 -0700, Ciaran O''Donnell
<Ci************ @discussions.mi crosoft.comwrot e:
Hey,
Jon Skeet is right with his suggestion about deriving from event args and
making you own delegate for the event.
Just to clarify: that's the normal approach if your class declares the
event and you have control over it. Otherwise, while you certainly could
proxy the event and copy the base EventArgs sub-class instance to a new
more-derived sub-class instance, IMHO it'd be better to just add a
parameter and pass the original EventArgs sub-class instance untouched.

The ambiguity is the reason I asked the OP what information he's trying to
pass and where it would come from. Basically, we don't know enough about
the OP's actual problem. If he's handling the Control.Click event,
creating a new EventArgs sub-class probably isn't the right way to go.

Pete
Jul 17 '08 #11
Sorry about the mistake Peter. I'll add it to the list of many times I should
have read the small print to avoid an embarassing or costly mistake.

Sincerest Apologies

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Peter Duniho" wrote:
On Thu, 17 Jul 2008 06:34:01 -0700, Ciaran O''Donnell
<Ci************ @discussions.mi crosoft.comwrot e:
errrrm.
I am NOT an MVP, and according to the Microsoft MVP awardies page, Peter
Duniho is not a current MVP holder
(https://mvp.support.microsoft.com/co...=peter+duniho).

Just FYI: that directory includes only those MVPs who have specifically
enabled their profiles as being publicly visible, which I haven't (there's
not actually any useful information in my profile, and it's not like I
feel a need to _prove_ to anyone I'm an MVP, so I never bothered to enable
it).

You seem to have covered everything else. :)

Pete
Jul 18 '08 #12
On Jul 17, 1:58*pm, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
My complete *guess* is that Peter won't go to the trouble of making his
profile public just to make a point, but I sincerely hope that if he
does so, you are ready to apologise for the insults quoted above.
I confirmed your public profile was set to private, so you can turn it
back on now.

Peter doesn't want my apology--he's a tough old coot and enjoys the
'intellectual repartee' of sparring with somebody who is at least his
equal in smarts, and in coding maybe will be some day!

RL
Jul 18 '08 #13
On Jul 18, 10:39*am, raylopez99 <raylope...@yah oo.comwrote:
My complete *guess* is that Peter won't go to the trouble of making his
profile public just to make a point, but I sincerely hope that if he
does so, you are ready to apologise for the insults quoted above.

I confirmed your public profile was set to private, so you can turn it
back on now.
Thank you.
Peter doesn't want my apology--he's a tough old coot and enjoys the
'intellectual repartee' of sparring with somebody who is at least his
equal in smarts, and in coding maybe will be some day!
Leaving your assertion of being "at least [Peter's] equal in smarts"
to one side, are you seriously happy to call someone a fraud and not
apologise for it when you know you're wrong? Part of having a
civilised debate is respecting those you're debating with - and part
of showing respect is apologising when you're wrong. That's true even
for technical inaccuracies, but I'd say it's doubly important when
you've made inaccurate personal assertions.

Jon
Jul 18 '08 #14
On Fri, 18 Jul 2008 02:39:52 -0700, raylopez99 <ra********@yah oo.com>
wrote:
On Jul 17, 1:58¬*pm, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
>My complete *guess* is that Peter won't go to the trouble of making his
profile public just to make a point, but I sincerely hope that if he
does so, you are ready to apologise for the insults quoted above.

I confirmed your public profile was set to private, so you can turn it
back on now.

Peter doesn't want my apology
Frankly Ray, it's not really a matter of what I want. It's true that I
have no real need of an apology from you, nor did I -- given your past
behavior -- actually expect one. But it's telling that given the
opportunity to offer one, you make a choice based on what you assert I
need or want, rather than what's the "right thing to do".

Given your participation in this newsgroup, my responses have been
targeted at just two goals: correcting misinformation, and trying to help
you improve your own communication skills (especially as they relate to
you apparently viewing yourself as a teacher). On the other hand, you
seem to revel in your own goal of prodding me with personal attacks.

I'm happy to ignore those attacks; after all, they say a lot more about
you than they do about me. But a person deserving of community respect
knows when they've crossed the line and _sincerely_ apologizes for it.

Now, I have my own personal thoughts on whether that really describes you
or not, but the fact is, if you're looking for credibility here, keeping
the bluster up even when you've made wildly false, personal accusations of
an individual is counter-productive to say the least. You really ought to
avoid the bluster altogether, but if you must engage in it, you ought to
at least equip yourself with the useful practice of apologizing when it's
gone wrong.

And again...I say this not for my own benefit, but for yours. I realize
it's difficult for you to see, but the two goals I described above really
do cover the extent of my intent. You have a determined interest in C#
programming and apparently the time and motivation to explore the language
and the framework. _If_ you could just take to heart some of the
criticisms and harness your powers for good, I think you could make some
real contributions here.

Pete
Jul 18 '08 #15
On Fri, 18 Jul 2008 02:23:02 -0700, Ciaran O''Donnell
<Ci************ @discussions.mi crosoft.comwrot e:
Sorry about the mistake Peter. I'll add it to the list of many times I
should
have read the small print to avoid an embarassing or costly mistake.
No problem at all. It was an honest mistake, and so I wouldn't call it
embarassing, nor did it seem costly (well, not to me or you, anyway :) ).
Jul 18 '08 #16
On Fri, 18 Jul 2008 09:41:17 -0700, raylopez99 <ra********@yah oo.com>
wrote:
On Jul 18, 9:27¬*am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
>I'm happy to ignore those attacks; after all, they say a lot more about¬*
you than they do about me. ¬*But a person deserving of community respect
knows when they've crossed the line and _sincerely_ apologizes for it.

OK, OKAY. Jeez I didn't realise you such a shrinking violet.
I'm not. You fail to get the point.
"I sincerely appologize" for flaming you. happy now?
I was happy before. Your quoted statement doesn't change that one way or
the other (nor does it seem sincere to me).

Until you fully comprehend what I actually wrote, I don't believe it will
be possible for you to offer a sincere apology. And it's clear you don't
comprehend what I wrote.

Pete
Jul 18 '08 #17
On Jul 18, 9:59*am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
>
Until you fully comprehend what I actually wrote, I don't believe it will*
be possible for you to offer a sincere apology. *And it's clear you don't *
comprehend what I wrote.
I'm REALLY sorry, OK? Besides I need guys like you to help me learn
C# and debug my code when I run into a brick wall, so I have to be
nice--self interest you know. So far though, I'm not having too many
problems with C# Forms, which seem to be more robust than the GUI
database stuff for C# (the frequent casting there seems terrible and
undocumented, and stuff is always not compiling even when copied from
a book).

RL
Jul 18 '08 #18
I am also having a similar problem.I would like to pass in an extra
parameter in my event handler being that I need the information
(curveArray = 2d array where each array has 64 values) to plot graphs on
the user interface. So heress the low down, I have a class called
CurveData that does calculations on data read from a unit via serial
port and returns a 2D array (curveArray) in the method called
initializeIgnCo mm. That information is passed into the event handler
getCurvesToolSt ripMenuItem_Cli ck1, sorted to a list, and that list is
used in plotCurves to generate a plot. I donít know if this is the best
way to go about this but I am unable to think of a way to get this
curveArray data without passing parameters in. So here is the event
handler code in my main form file as well as methods called in the event
handler:

//EVENT HANDLER
private void getCurvesToolSt ripMenuItem_Cli ck1(object sender, int[,]
curveArray)
{
comm.DisplayWin dow = rtbDisplay;
try
{
if (serialPort1.Is Open)
{
comm.initialize IgnComm(serialP ort1);
plotCurves(zedG raphControl1, curveArray);
}
else
{
MessageBox.Show ("Error: COM port closed.");
return; // bail out
}
}
catch (System.Excepti on ex)
{
MessageBox.Show ("Error - findIgnButton_C lick Exception:
" + ex);
}

}
#endregion

private void plotCurves(ZedG raphControl zgc, int[,] curveArray)
{
GraphPane plotCurve = zgc.GraphPane; //Get a
reference to the GraphPane

// Set the Titles
plotCurve.Title .Text = "DFS726 IGNITION TIMING\n";
plotCurve.XAxis .Title.Text = "RPM(x100)" ;
plotCurve.YAxis .Title.Text = "Advance Angle(Degrees BTDC)";

PointPairList curve1 = new PointPairList() ; //Create
curve1 list
sortData(curveA rray); //Sort data into
list for plotting

LineItem ignCurve = plotCurve.AddCu rve("WOT Curve 4",
curve1, Color.Red, SymbolType.Diam ond);
zgc.AxisChange( );

}
#endregion

private PointPairList sortData(int[,] curveArray)
{
int numberOfCurves = 8;
int[,] advDegBTDC = new int[numberOfCurves, 8];
int[,] rpmValues = new int[numberOfCurves, 8];
int curveNumber = 0;
int arrayIndex = 0;
int genArrayIndex = 0;

// Copy data from rpmArray and advArray into rpmValues and
advDegBTDC arrays used for plots
for (curveNumber = 0; curveNumber < numberOfCurves;
curveNumber++)
{
for (arrayIndex = 0; arrayIndex < 8; arrayIndex++)
{
advDegBTDC[curveNumber,arr ayIndex] =
curveArray[0,genArrayIndex];
rpmValues[curveNumber,arr ayIndex] =
curveArray[1,genArrayIndex];
genArrayIndex++ ;
}
}
PointPairList list1 = new PointPairList() ;

// TEST: Just sending the first curve (8 data points) to
list1 to graph
for (int i = 0; i < 8; i++)
{
list1.Add(rpmVa lues[0,i], advDegBTDC[0,i]);
}
return list1;

}
Iíve only been using C# for a couple weeks so forgive me if my coding is
not up to proper standards. Thanks in advance!


*** Sent via Developersdex http://www.developersdex.com ***
Oct 29 '08 #19
"dondigitec h LaPel" <dl****@dynaonl ine.comwrote in message
news:uE******** ******@TK2MSFTN GP04.phx.gbl...
>I am also having a similar problem.I would like to pass in an extra
parameter in my event handler
I don't see the post that you replied to, so I'm making assumptions about
the original question.

My first assumption is that you're defining your OWN event handler and not
dealing with an event model that is out of your control. The .NET standard
is to pass only two parameters in an event handler: an instance of Object
that represents the object which raised the event (the sender) and an
instance of EventArgs--or a class derived from EventArgs--which contains all
the necessary information that a subscriber (consumer) might need. The part
about derived classes is important. If you need to provide information to
your event consumers then you should derive a class from EventArgs and add
properties to that class to hold that necessary data. (Well, unless the
Framework already provides a derived class which gives you exactly what you
need.)

Most of the time these properties are for one-way information: from the
sender to the consumer, but sometimes the consumer will pass information
back to the sender (an event which can be canceled is a perfect example of
this).
Oct 29 '08 #20

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

Similar topics

7
49591
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. The question is about best practices for passing parameters to an event function. I have, say, the following HTML:
2
2001
by: Adi | last post by:
Okay, this issue has been annoying me for a little while now. I need it to work on Mozilla 1.6 & IE 6 This is what I would like to be able to do: var row = document.createElement("TR"); var tdImage = document.createElement("TD"); var img = document.createElement("IMG"); img.src = "results.gif"; var theA = document.createElement("A");
7
4677
by: mg | last post by:
How can I call an event handler (e.g., Button1_Click) programmatically. That is, without having to click on the button with the mouse.
2
3747
by: Jose Suero | last post by:
Hi all I have a dynamically created button, I can add an event handler with: AddHandler button.click, AddressOf static_function This works great, but what I need is to create a function that takes the control, the event and the function as parameters, something like: function addevent(control as object, event as string, functionname as string)
15
26524
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
5
3872
by: james | last post by:
Hello, I am having a little trouble creating an event handler for a context menu toolstripmenuitem. I've seen various tutorials and so on, but I keep getting a bit stuck! So far I have a second class defining the eventargs I want to use: public class ApptEventArgs : EventArgs{ public int ApptUID; public String ApptOp;
2
2083
by: fusillo | last post by:
My code pass a value of a variable to the event handler's argument by means of eval statement here's: //statements setting evt for (var i=0; i<evt.periodi.length; i++){ //evt.periodi is an array of objs a=document.createElement("a"); a.onclick=eval('function (){ cancellaCal(' + evt.periodi.id_evt_cal
5
5206
by: Tenacious | last post by:
I am trying to shutdown a database server in the Application_End event handler on the Global.asax page. So far I am trying this only on the development server that comes with Visual Studio 2005. When I close the browser, this does not cause the Application_End event to trigger. It also will not occur when I shut down the development server. At this point the application is no longer running, so why didn't the event handler ever get called?...
7
1841
by: Andrus | last post by:
I noticed that DataGridView CellValidated() and other event handler first parameter is object: Grid.CellValidated+=new DataGridViewCellEventHandler(Grid_CellValidated); .... void Grid_CellValidated(object sender, DataGridViewCellEventArgs e) { .....
0
9903
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
9754
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10375
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
9526
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...
1
7927
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7084
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
4567
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
4168
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3194
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.