473,657 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
SelectedIndexCh anged 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 2455
Hi Jose,
it is not possible for you to get to the MulticastDelega te 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
SelectedIndexCh anged 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 implementedIExt enderProvider 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 ActionSecurityL evel, 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.EventHan dler [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 programmaticall y 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.ActionSecu rityLevel User.ActionSecu rityLevel)
c.click+=new system.EventHan dler(myNonActio nCode); --we have here
added a new handler
c.click-=new system.EventHan dler(????????); --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*********@di scussions.micro soft.comwrote in message
news:6B******** *************** ***********@mic rosoft.com...
Hi Jose,
it is not possible for you to get to the MulticastDelega te 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
SelectedIndexC hanged del dropDown.

so, automatically it gets created the two event handler methods for these
subscription s.
my point is that i would like to be able in runtime to find those two
subscription s, 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*********@di scussions.micro soft.comwrote in message
news:6B******** *************** ***********@mic rosoft.com...
Hi Jose,
it is not possible for you to get to the MulticastDelega te 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
SelectedIndexC hanged del dropDown.

so, automatically it gets created the two event handler methods for these
subscription s.
my point is that i would like to be able in runtime to find those two
subscription s, 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
294
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 independant response) is received, the poll timer and retry timer are stopped and the poll timer is started again. If the retry timer times out, the poll is resent. This control is put on seperate tab pages which can be added or deleted by the...
1
4266
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 button that hides the current form and shows the second form. On showing the second form for the first time the On_Form_Load event is kicked off and the data in the two textboxes is added up and displayed in a label. A button on the second form...
3
2380
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 things. The method I am writing queries a large dataset. As part of my feedback to the user, I am updating the status bar when the connection is made and the dataset is actually retrieved. The dataset retrieval method I have placed on a separate...
8
2827
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 issue...also our clients would like to use a lot of client side events like sorting, searching text, save each row on tab out of a row, use the auto correct feature... after intial r&d we feel that using a Grid Control in WinForms would be a...
5
8788
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 controls on it and the function takes a long time to beexecuted. This is my function Public Function FindControl(ByVal oControls As Control.ControlCollection, ByVal strControlName As String) As Control
6
2797
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 key like 'libPath'. As far as winform and asp.net share the same common base class for settings, SettingsBase, how to manage this ? For winform the value should be set in app.config and for web site in
2
3723
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 usercontrol will fire this event upon certain action by the user. I tried to let the aspx page subscribe to this event via <script for="winObj1" event="DoEvent()" language="javascript"> window.alert("window control event happen!");
1
365
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 app that calls a web service which creates creates a GUID and caches it, then passes the GUID back to the winform. then it opens a aspx page and passes the GUID as a parameter. this GUID is only cached for about 10 seconds and must be still...
7
1913
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 complete copy of the main form so the user may start a second lengthy calculation if desired. I have a menu item to "Launch New Workspace" but I am having difficulty implementing this. I detail my experiments below; any suggestions on the proper...
0
8425
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
8326
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
8845
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
8743
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
8522
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
7355
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
6177
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
5647
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
2745
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

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.