|
Delegates hold a list of delegates (called an invocation list) which are called when the delegate itself is invoked.
The += YourMethod adds a delegate to your method to the event's (an event is just a specialized delegate) invocation list.
using System;
public class EventRaisingClass
{
public event EventHandler SomethingChanged;
public void ChangeSomething()
{
OnSomethingChanged(EventArgs.Empty);
}
protected virtual void OnSomethingChanged(EventArgs e)
{
EventHandler eh = SomethingChanged;
if (eh != null)
eh(this, e);
}
}
using System;
public class SubscribingClass
{
private EventRaisingClass eventRaisingInstance;
public SubscribingClass()
{
eventRaisingInstance = new EventRaisingClass();
eventRaisingInstance.SomethingChanged += EventRaisingInstanceSomethingChanged;
}
private void EventRaisingInstanceSomethingChanged(object sender, EventArgs e)
{
Console.WriteLine("Something Changed");
}
public void Update()
{
eventRaisingInstance.ChangeSomething();
}
}
In your example the Button is the EventRaisingClass, that code is part of the framework but operates in exactly the same way.
Warning: Because a reference to an item (method) of our subscribing class is now held in another class instance, it will not be eligible garbage collection until the raising class instance is collected. If you require the subscribing instance to be eligible for collection beore that time then you can remove the delegate from the event with -= YourMethod . Not needed often, but can cause suprises if you are not aware of this.
|
|
|
|
|
A fine explanation. One question though. How / Where Update() is called here?
This world is going to explode due to international politics, SOON.
|
|
|
|
|
It's not in the sample code, but it could be called from anywhere that has access to an instance of that class (or by code elsewhere within the class).
|
|
|
|
|
Hello everybody. im working on graduation project and i have trouble to locate and find iris image. where can i find libraries to find iris image? please answer this very important for me i must graduate this year but i can't finished my project yet.
|
|
|
|
|
A quick Google search for "face recognition" or "eye recognition" will probably find what you are looking for.
|
|
|
|
|
Hi All,
Firstly I don't want to post in wrong forum for set up, installer questions which this is I have posted here until I can find a more approiate forum on CP. I have an executable I have written/hacked with help to test for a driver, I would like to know how to ensure it gets excuted by the installer (this is related to question I asked Pete O'Hanland last week I am NOT trying to do anything nasty!).
Glenn
|
|
|
|
|
I would execute it as part of a custom installer step. You can find an example of code here[^] that starts an external process.
|
|
|
|
|
Thanks for that, is there a forum on CP for installers and things, the closest I found was System Admin?
Glenn
|
|
|
|
|
There isn't. This form has been regularly used for installer questions, so I think we can cut you a little slack.
|
|
|
|
|
Bit OT but is MIL OK?
Glenn
|
|
|
|
|
Well, she had the operation yesterday, and according to the nurses, they've removed the bits they needed to remove. Unfortunately we could get no more details because this was last night, so we're waiting to speak to her consultant today for more details. She's hooked up to the pain meds, so we're hoping that she's had a comfortable night.
Thanks for asking.
|
|
|
|
|
No Worries! been there myself (don't really want to go there again but...)
Glenn
|
|
|
|
|
i want make a class for use textbox act as masketextbox
|
|
|
|
|
You already have a Masked Text Box control available[^].
You should not need to create a separate control unless this is for academic purposes.
|
|
|
|
|
What technology? ASP.NET? WPF? Windows Forms? Silverlight?
|
|
|
|
|
|
I have created an interface where user can chose the required data to be exported to excel.
If in future, user select a new data to be exported which the new data is already included in the previous data, the excel file must not replace bt the current one. If the new data selected is not included in the previous data, the excel file should update the data instead of replace it.
Any idea of how can I do that?
|
|
|
|
|
Member 9169887 wrote: Any idea of how can I do that?
Open your excel file, loop through all existing data and see whether it has changed (and needs be updated)
Easiest way to read an existing excel-file would be using JET.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I AM CREATING A QUERY SORTER IN WPF C# ...
FOR THIS I USED DATAGRID AND IN DATAGRID TEMPLATE COLUMN I USED AN IMAGE(BLANK.BMP). ON CLICKING, I WANT BLANK.BMP TO BE CHANGED INTO ASCENDING.BMP , AND ASCENDING.BMP TO DESCENDING.BMP , AND DESCENDING.BMO TO BLANK.BMP. HOW CAN I PERFORM THIS FUNCTIONALITY OF IMAGE CHANGING IN DATAGRID??
|
|
|
|
|
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Okay, here's what I would do if I was feeling quirky. I would assign each image a number, and I would then use an ImageConverter to convert the number into a bitmap. Finally, on the header click, I would use a custom sorter to simply reassign these values - a quick bit of LINQ would see this through.
|
|
|
|
|
How Can i link between data in dataset's tables and datagrid in WFP
khaled
|
|
|
|
|
|
You might find this[^] article to be of some benefit.
|
|
|
|
|
I am working on a program which takes user input and validates the user input against data I have loaded into a hashtable. I'm running into issues on where I put my hashtable code; the reading of the file and moving data into the hashtable so that I can still reference the hashtable at a button click level. I've currently have the hashtable code (creation and adding)on the form.cs;
Basically the user will input a value(key) and I will pass back the value associated with the key in the hashtable.
I'm very much a beginner with C# programming and have not worked much with forms Please help!!
|
|
|
|