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

Home Posts Topics Members FAQ

EventHandling problem : Java has solution but what about Microsoft???

Hi,
I have added few of the events in some control, example code is:
btnControl.GotF ocus +=new EventHandler(Ev entHandlingMeth od);
btnControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
lblControl.Clic k +=new EventHandler(Ev entHandlingMeth od);

private void EventHandlingMe thod(object sender, EventArgs e)
{
.......
}

btnControl = Button object, lblControl = Lable object

Now the problem is: I am adding the same event handler method in all events for btnControl and lblControl too.

now in EventHandlingMe thod method, i can find which control is using sender but now if i want to put some switch cases in the method for Event Name then I have no any such information in the eventargs or anyother way....

Can someone help/guide me to get the event name?

Is it possible? if yes then how? If no, then any work around?

Thanks in Advance

Regards,
Mahesh Devjibhai Dhola

Nov 29 '05 #1
21 1345
(some newsgroups trimmed - this really wasn't appropriate for all the
listed groups)

Mahesh Devjibhai Dhola [MVP] wrote:
Hi,
I have added few of the events in some control, example code is:
btnControl.GotF ocus +=new EventHandler(Ev entHandlingMeth od);
btnControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
lblControl.Clic k +=new EventHandler(Ev entHandlingMeth od);

private void EventHandlingMe thod(object sender, EventArgs e)
{
.......
}

btnControl = Button object, lblControl = Lable object

Now the problem is: I am adding the same event handler method in all events for btnControl and lblControl too.

now in EventHandlingMe thod method, i can find which control is using sender but now if i want to put some switch cases in the method for Event Name then I have no any such information in the eventargs or anyother way....

Can someone help/guide me to get the event name?

Is it possible? if yes then how? If no, then any work around?


Your design is bad. Methods should do one thing. If you actually want
the same thing to happen on GotFocus and on Click, fine. If you want
*different* things to happen, use *different* procedures. If there is
some common and some different functionality, put the common
functionality in a separate procedure called from both event handlers.

You shouldn't treat event handlers like a substitute for a Windows
message loop, that has to handle everything that can possible happen.
The GotFocus event handler should do what is required on GotFocus; the
Click event handler should do what is required on Click; and so on.

--
Larry Lard
Replies to group please

Nov 29 '05 #2
"Mahesh Devjibhai Dhola [MVP]" <dh*********@ho tmail.com> schrieb:
I have added few of the events in some control, example code is:
btnControl.GotF ocus +=new EventHandler(Ev entHandlingMeth od);
btnControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
lblControl.Clic k +=new EventHandler(Ev entHandlingMeth od);

private void EventHandlingMe thod(object sender, EventArgs e)
{
.......
}

btnControl = Button object, lblControl = Lable object

Now the problem is: I am adding the same event handler method in all events
for btnControl and lblControl too.

now in EventHandlingMe thod method, i can find which control is using sender
but now if i want to put some switch cases in the method for Event Name then
I have no any such information in the eventargs or anyother way....
=======

I am curious which sense handling different events of different controls in
the same event handler would make. Instead, add separate event handlers for
all event types, not just delegate types. This means separate handlers for
controls' 'Click' and 'GotFocus' events.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 29 '05 #3
If you need to do different things depending on the event, why not have different event handlers? You can place common code into a method that both event handlers can call.

I understand what you are saying, but it just doesn't seem like a big deal. It is very easy to work around, and most of the time it is not even an issue because you either need different code in the handler anyway, or the events have different signatures, etc.
"Mahesh Devjibhai Dhola [MVP]" <dh*********@ho tmail.com> wrote in message news:uL******** ******@TK2MSFTN GP14.phx.gbl...
Hi,
I have added few of the events in some control, example code is:
btnControl.GotF ocus +=new EventHandler(Ev entHandlingMeth od);
btnControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
lblControl.Clic k +=new EventHandler(Ev entHandlingMeth od);

private void EventHandlingMe thod(object sender, EventArgs e)
{
.......
}

btnControl = Button object, lblControl = Lable object

Now the problem is: I am adding the same event handler method in all events for btnControl and lblControl too.

now in EventHandlingMe thod method, i can find which control is using sender but now if i want to put some switch cases in the method for Event Name then I have no any such information in the eventargs or anyother way....

Can someone help/guide me to get the event name?

Is it possible? if yes then how? If no, then any work around?

Thanks in Advance

Regards,
Mahesh Devjibhai Dhola

Nov 29 '05 #4
Mahesh ,

I agree with what Herfried and Marina have written with regards to different
controls of different types.

The one place where I do find it useful to use a single event handler for
multiple controls is with Button Controls. Take a look at the Button Command
event. You can pass different CommandName and CommandArgument strings for
each button while using the same Button Command event handler.

This works with traditional Button controls as well as Link Buttons and
Image Buttons.

--

Andrew Robinson
www.binaryocean.com
www.bellinghamdotnet.org
"Mahesh Devjibhai Dhola [MVP]" <dh*********@ho tmail.com> wrote in message
news:uL******** ******@TK2MSFTN GP14.phx.gbl...
Hi,
I have added few of the events in some control, example code is:
btnControl.GotF ocus +=new EventHandler(Ev entHandlingMeth od);
btnControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
lblControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
private void EventHandlingMe thod(object sender, EventArgs e)
{
.......
}
btnControl = Button object, lblControl = Lable object
Now the problem is: I am adding the same event handler method in all events
for btnControl and lblControl too.
now in EventHandlingMe thod method, i can find which control is using sender
but now if i want to put some switch cases in the method for Event Name then
I have no any such information in the eventargs or anyother way....
Can someone help/guide me to get the event name?
Is it possible? if yes then how? If no, then any work around?
Thanks in Advance
Regards,
Mahesh Devjibhai Dhola
Nov 29 '05 #5
Dear,
The Microsoft Event handling framework allows me to do this what you suggest
but some time, its possible to have such requirement so its not the matter
of sense but its my need so if you can suggest me the woraround for my
prolme then it will be helpful to me.

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
"Mahesh Devjibhai Dhola [MVP]" <dh*********@ho tmail.com> schrieb:
I have added few of the events in some control, example code is:
btnControl.GotF ocus +=new EventHandler(Ev entHandlingMeth od);
btnControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
lblControl.Clic k +=new EventHandler(Ev entHandlingMeth od);

private void EventHandlingMe thod(object sender, EventArgs e)
{
.......
}

btnControl = Button object, lblControl = Lable object

Now the problem is: I am adding the same event handler method in all events for btnControl and lblControl too.

now in EventHandlingMe thod method, i can find which control is using sender but now if i want to put some switch cases in the method for Event Name then I have no any such information in the eventargs or anyother way....
=======

I am curious which sense handling different events of different controls in the same event handler would make. Instead, add separate event handlers for all event types, not just delegate types. This means separate handlers for controls' 'Click' and 'GotFocus' events.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 30 '05 #6
Dear,
Your design is good or bad, it depends on requirement.
I know what is good and bad design for my situation. I am creating my own
framework and thats why i need such help.
This is very simple and general need to have "Event name" in some cases. I
am surprised that all Event has common property and thats Event name and
EventArgs is simply derived from Object class, instead it should have
atleast name property.
So, please dont concentrate on design and if possible, help me to find out
the answer. That is my need and anyhow i want to solve it.

Thanking you all for your kind support.

"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
(some newsgroups trimmed - this really wasn't appropriate for all the
listed groups)

Mahesh Devjibhai Dhola [MVP] wrote:
Hi,
I have added few of the events in some control, example code is:
btnControl.GotF ocus +=new EventHandler(Ev entHandlingMeth od);
btnControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
lblControl.Clic k +=new EventHandler(Ev entHandlingMeth od);

private void EventHandlingMe thod(object sender, EventArgs e)
{
.......
}

btnControl = Button object, lblControl = Lable object

Now the problem is: I am adding the same event handler method in all events for btnControl and lblControl too.
now in EventHandlingMe thod method, i can find which control is using sender but now if i want to put some switch cases in the method for Event
Name then I have no any such information in the eventargs or anyother
way....
Can someone help/guide me to get the event name?

Is it possible? if yes then how? If no, then any work around?


Your design is bad. Methods should do one thing. If you actually want
the same thing to happen on GotFocus and on Click, fine. If you want
*different* things to happen, use *different* procedures. If there is
some common and some different functionality, put the common
functionality in a separate procedure called from both event handlers.

You shouldn't treat event handlers like a substitute for a Windows
message loop, that has to handle everything that can possible happen.
The GotFocus event handler should do what is required on GotFocus; the
Click event handler should do what is required on Click; and so on.

--
Larry Lard
Replies to group please

Nov 30 '05 #7
Dear,
I am creating my own framework and its not centric to Buttton or some
control only. It will be applicable to all the events of all the controls.
So i need one common place which will be a common event handler method for
all and from that method my framework will work ahead by checking the sender
control and event name and i am doing lot other things at event time and i
will need more info than just sender and eventargs so i need to have such
method and switch case for event names.
For the same type of situation, java allows to have event name but i am
wondering why Microsoft has not such a simple provision in EventArgs??

"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:Oi******** ******@TK2MSFTN GP09.phx.gbl...
Mahesh ,

I agree with what Herfried and Marina have written with regards to different controls of different types.

The one place where I do find it useful to use a single event handler for
multiple controls is with Button Controls. Take a look at the Button Command event. You can pass different CommandName and CommandArgument strings for
each button while using the same Button Command event handler.

This works with traditional Button controls as well as Link Buttons and
Image Buttons.

--

Andrew Robinson
www.binaryocean.com
www.bellinghamdotnet.org
"Mahesh Devjibhai Dhola [MVP]" <dh*********@ho tmail.com> wrote in message
news:uL******** ******@TK2MSFTN GP14.phx.gbl...
Hi,
I have added few of the events in some control, example code is:
btnControl.GotF ocus +=new EventHandler(Ev entHandlingMeth od);
btnControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
lblControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
private void EventHandlingMe thod(object sender, EventArgs e)
{
.......
}
btnControl = Button object, lblControl = Lable object
Now the problem is: I am adding the same event handler method in all events for btnControl and lblControl too.
now in EventHandlingMe thod method, i can find which control is using sender but now if i want to put some switch cases in the method for Event Name then I have no any such information in the eventargs or anyother way....
Can someone help/guide me to get the event name?
Is it possible? if yes then how? If no, then any work around?
Thanks in Advance
Regards,
Mahesh Devjibhai Dhola

Nov 30 '05 #8
"Mahesh Devjibhai Dhola [MVP]" <dh*********@ho tmail.com> schrieb:
The Microsoft Event handling framework allows me to do this what you
suggest
but some time, its possible to have such requirement so its not the matter
of sense but its my need so if you can suggest me the woraround for my
prolme then it will be helpful to me.


No, I can't suggest a workaround, because each workaround would be an ugly
hack I would not want to see getting into production code.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 30 '05 #9
EventArgs is just the base class for event arguments. You could perhaps
define your own class that would pass the information you need.

I won't discuss this design but it looks like you could also inherits from
those controls and change the On<Event> method ?

--
Patrice

"Mahesh Devjibhai Dhola [MVP]" <dh*********@ho tmail.com> a écrit dans le
message de news:O0******** *****@TK2MSFTNG P10.phx.gbl...
Dear,
I am creating my own framework and its not centric to Buttton or some
control only. It will be applicable to all the events of all the controls.
So i need one common place which will be a common event handler method for
all and from that method my framework will work ahead by checking the sender control and event name and i am doing lot other things at event time and i
will need more info than just sender and eventargs so i need to have such
method and switch case for event names.
For the same type of situation, java allows to have event name but i am
wondering why Microsoft has not such a simple provision in EventArgs??

"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:Oi******** ******@TK2MSFTN GP09.phx.gbl...
Mahesh ,

I agree with what Herfried and Marina have written with regards to

different
controls of different types.

The one place where I do find it useful to use a single event handler for multiple controls is with Button Controls. Take a look at the Button

Command
event. You can pass different CommandName and CommandArgument strings for each button while using the same Button Command event handler.

This works with traditional Button controls as well as Link Buttons and
Image Buttons.

--

Andrew Robinson
www.binaryocean.com
www.bellinghamdotnet.org
"Mahesh Devjibhai Dhola [MVP]" <dh*********@ho tmail.com> wrote in message news:uL******** ******@TK2MSFTN GP14.phx.gbl...
Hi,
I have added few of the events in some control, example code is:
btnControl.GotF ocus +=new EventHandler(Ev entHandlingMeth od);
btnControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
lblControl.Clic k +=new EventHandler(Ev entHandlingMeth od);
private void EventHandlingMe thod(object sender, EventArgs e)
{
.......
}
btnControl = Button object, lblControl = Lable object
Now the problem is: I am adding the same event handler method in all

events
for btnControl and lblControl too.
now in EventHandlingMe thod method, i can find which control is using

sender
but now if i want to put some switch cases in the method for Event Name

then
I have no any such information in the eventargs or anyother way....
Can someone help/guide me to get the event name?
Is it possible? if yes then how? If no, then any work around?
Thanks in Advance
Regards,
Mahesh Devjibhai Dhola


Nov 30 '05 #10

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

Similar topics

4
2411
by: Marc Tanner | last post by:
Hello, I am currently working on a eventhandling system or something similar, and have the problem of loosing scope. I have read many interesting posts on this group and the faq article about closure, but it seems that i have still not understood everything. Below is my attempt to preserve the scope but it's not really nice and i think with the use of closure could it be done better. But at the moment i am quite confused and hope that...
3
1184
by: Claes Rådström | last post by:
Hi ! We have a base class that derives from System.Web.UI.Page Alla our pages derives from it. In our base class we want to have an access check, (own) , to verfy user access to the derived page. We want this in the base class so that the programmer cant forget to implement it. => we want a page load in the base class to fire first, if access is granted
12
1283
by: Mahesh Devjibhai Dhola [MVP] | last post by:
Hi, I have added few of the events in some control, example code is: btnControl.GotFocus +=new EventHandler(EventHandlingMethod); btnControl.Click +=new EventHandler(EventHandlingMethod); lblControl.Click +=new EventHandler(EventHandlingMethod); private void EventHandlingMethod(object sender, EventArgs e) { ....... }
0
8609
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
9166
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...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
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
8871
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
7737
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
5861
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();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2007
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.