473,396 Members | 2,018 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.

GET WINFORM SUBSCRIPTIONS TO EVENTS

Hello.

I would like to know how could i get all the subscriptions that my form has
with the events of their controls.

For example.

I have a form with a textbox, a button and a dropdown. I create a
subscription to the Click event of the Button and another to the
SelectedIndexChanged del dropDown.

so, automatically it gets created the two event handler methods for these
subscriptions.
my point is that i would like to be able in runtime to find those two
subscriptions, for example, and delete them in runtime. does it make sense?
Dec 8 '06 #1
3 2438
Hi Jose,
it is not possible for you to get to the MulticastDelegate instance which
is being used for the events in your winform controls to see which delegates
are currently in it's invocation list. You can use the -= syntax to remove
delegates, so if you know which delegates you want to remove you can use -=
to remove them this will work even if the delegates are not currently in the
events underlying Multicast delegate. You best bet would be to store the
delegates you want to remove in your form and then just call -= when you want
to remove them.

Mark.
--
http://www.markdawson.org
"Jose Fernandez" wrote:
Hello.

I would like to know how could i get all the subscriptions that my form has
with the events of their controls.

For example.

I have a form with a textbox, a button and a dropdown. I create a
subscription to the Click event of the Button and another to the
SelectedIndexChanged del dropDown.

so, automatically it gets created the two event handler methods for these
subscriptions.
my point is that i would like to be able in runtime to find those two
subscriptions, for example, and delete them in runtime. does it make sense?
Dec 8 '06 #2
Well..

I want something that i can write once, and use in every form, in every
control.
I have already implementedIExtenderProvider to set the security values in
design time for every control in any forms that i load. Then, what i do, is
go to the database, fetch the security values for that user, store them in a
IPrincipal object that i created and everytime i load a form, i compare the
security values of the user with those in every control. That works
perfect!. I created a method in a base form, all my forms inherits from it.
So, when i load a form, i call that method, pass the parameters that i need
and voila... my controls appear enabled, disabled, visible... depends on the
criteria. So, one piece of code, 5 lines, just works for every form and
every control.

I wanted then, due to the ActionSecurityLevel, to be able to change in
runtime the method to be called when you click on a button. right? 'Cause i
don't wanna be writing code everytime i create a subscription to an event. I
know how to add in runtime an eventHandler to a control... as easy as
Control.[event]+=new System.EventHandler [or any other
handler](the_method_to_call). That's fine. But doesn't prevent the code to
perform any other method that had a subscription to that event.

So, i know also that you can programmatically unsubscribe an event by
Control.[event]-=.......... the problem is that when i am iterating thru
controls, i don't have the way to pass or know which handler[method] is
dealing with the subscription. I could do some trick. Like... once i hace
the control (in my iteration security checking code) i can find its instance
name, ok? lets say button1. ok. then i can ASSUME that when i created that
subscription it took by default the _Click suffix... so, it would be
button1_Click.
Next step would be to cast to Handler this string "button1_Click". So, i
would have to create a Method, returning a handler after i pass a parameter
type string with the "name" i "guess" it's going to have the handler. does
it makes sense?

let's put some pseudo code.

let's assume all controls are button.
foreach(Control c in form.Controls)
if(c.ActionSecurityLevel User.ActionSecurityLevel)
c.click+=new system.EventHandler(myNonActionCode); --we have here
added a new handler
c.click-=new system.EventHandler(????????); --i can't write a
handler manually since you are iterating. i don't know the handler method
since i don't "know" its list of handlers. we can't access list of
suscription from the form to that control event.

MY "SILLY" SOLUTION

in that line of code (???????).. well i would set a method in there that
would return the eventhandler.

private EventHandler getEventHandler(string assumedName) -remember,
assumed name is the concatenation of instance name of the control and
"_Click"

so, this method supposedly will return a handler with the name by default
that VS gives to a subscription to a click event. for example, for button
instance button1, would be button1_Click.
"Mark R. Dawson" <Ma*********@discussions.microsoft.comwrote in message
news:6B**********************************@microsof t.com...
Hi Jose,
it is not possible for you to get to the MulticastDelegate instance which
is being used for the events in your winform controls to see which
delegates
are currently in it's invocation list. You can use the -= syntax to
remove
delegates, so if you know which delegates you want to remove you can
use -=
to remove them this will work even if the delegates are not currently in
the
events underlying Multicast delegate. You best bet would be to store the
delegates you want to remove in your form and then just call -= when you
want
to remove them.

Mark.
--
http://www.markdawson.org
"Jose Fernandez" wrote:
>Hello.

I would like to know how could i get all the subscriptions that my form
has
with the events of their controls.

For example.

I have a form with a textbox, a button and a dropdown. I create a
subscription to the Click event of the Button and another to the
SelectedIndexChanged del dropDown.

so, automatically it gets created the two event handler methods for these
subscriptions.
my point is that i would like to be able in runtime to find those two
subscriptions, for example, and delete them in runtime. does it make
sense?

Dec 8 '06 #3
Hi Mark and Jose,
Actually this is what I thought too before I decided to delve into the
problem.

See the article in Windows Forms Tips and Tricks for enlightenment.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Mark R. Dawson" <Ma*********@discussions.microsoft.comwrote in message
news:6B**********************************@microsof t.com...
Hi Jose,
it is not possible for you to get to the MulticastDelegate instance which
is being used for the events in your winform controls to see which
delegates
are currently in it's invocation list. You can use the -= syntax to
remove
delegates, so if you know which delegates you want to remove you can
use -=
to remove them this will work even if the delegates are not currently in
the
events underlying Multicast delegate. You best bet would be to store the
delegates you want to remove in your form and then just call -= when you
want
to remove them.

Mark.
--
http://www.markdawson.org
"Jose Fernandez" wrote:
>Hello.

I would like to know how could i get all the subscriptions that my form
has
with the events of their controls.

For example.

I have a form with a textbox, a button and a dropdown. I create a
subscription to the Click event of the Button and another to the
SelectedIndexChanged del dropDown.

so, automatically it gets created the two event handler methods for these
subscriptions.
my point is that i would like to be able in runtime to find those two
subscriptions, for example, and delete them in runtime. does it make
sense?

Dec 8 '06 #4

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

Similar topics

2
by: Michael Huslig | last post by:
I have a C++.net user control which has two winform timers in it. When the 'poll' timer ticks, it stops itself, sends out a poll, and starts a 'retry' timer. When the response to the poll (or an...
1
by: Will | last post by:
Not sure the easiest way to ask this so I will give a small example of what I want to accomplish. Create a VB.Net WinForm Application with two forms. On the first form, two textboxes and a...
3
by: Elliot Rodriguez | last post by:
Hi: I am writing a WinForm app that contains a DataGrid control and a StatusBar control. My goal is to update the status bar using events from a separate class, as well as some other simple...
8
by: Sunil Menon | last post by:
Dear All, We are developing applications in ASP.Net...in one of our applications we would like to use a GridControl...we have tried to use a Server-Side Grid control but found the speed to be an...
5
by: Marc Robitaille | last post by:
Hello, Is there better a way of finding a control on WinForm than to use a recursive method on the controls collection property? I ask this question because I have winforms which have many...
6
by: WT | last post by:
Hello, Using VS2005. I have an assembly library that can be called from a Web site asp.net application or from a winform application. From this library I need to retrieve a path using simply a...
2
by: jyanmin.fang | last post by:
Hi, In my current project, I need to embed an .NET winform usercontrol in the aspx page (via <Objecttag). This winform usercontrol has an event called DoEvent (void DoEvent()). This winform...
1
by: moondaddy | last post by:
I had to repost this becuase I renewed-changed my msdn alias. Also, the asnwer in the other past did not understand what I'm trying to do, so I'll attempt to clarify. I have a .net 2.0 winforms...
7
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have a WinForm application that, depending on user actions, may spin for a while doing extensive calculations, showing a progress bar in the meantime. I would like to be able to launch a second...
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?
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
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,...
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
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...

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.