jtran007
asked on
C# delegate and event
Hi,
I am not sure what this code means:
public delegate void FirmwareDownloadProgressDe legate(obj ect sender, int value);
private event FirmwareDownloadProgressDe legate m_FirmwareDownloadProgress ;
public event FirmwareDownloadProgressDe legate FirmwareDownloadProgress
{
add { m_FirmwareDownloadProgress += new FirmwareDownloadProgressDe legate(val ue); }
remove { m_FirmwareDownloadProgress -= new FirmwareDownloadProgressDe legate(val ue); }
}
These functions are defined in a class which I will instanstiate . How can I use the value?
I am new to C# ,please help
JT
I am not sure what this code means:
public delegate void FirmwareDownloadProgressDe
private event FirmwareDownloadProgressDe
public event FirmwareDownloadProgressDe
{
add { m_FirmwareDownloadProgress
remove { m_FirmwareDownloadProgress
}
These functions are defined in a class which I will instanstiate . How can I use the value?
I am new to C# ,please help
JT
ASKER
Hi ,
Suppose I am a client of this class, how do I subscribe to use this class event?
Could you please give me an example?
Thanks,
JT
Suppose I am a client of this class, how do I subscribe to use this class event?
Could you please give me an example?
Thanks,
JT
sure...
Let's say that you have a class MyClass that has your delegate and an event defined.
In your class MyClient you'll say something like this:
MyClass.MyEventName += <name of a function that will handle your event>;
A hint, when you subscribe to an event, after you press +=, hit Tab key couple of times. Visual Studio will automatically create an event handler function for you based on the event you are subscribing to.
Let's say that you have a class MyClass that has your delegate and an event defined.
In your class MyClient you'll say something like this:
MyClass.MyEventName += <name of a function that will handle your event>;
A hint, when you subscribe to an event, after you press +=, hit Tab key couple of times. Visual Studio will automatically create an event handler function for you based on the event you are subscribing to.
ASKER
Hi,
So I can use like:
void Adt42To45_FirmwareDownload Progress(o bject sender, int value)
{
progressBar.Value = value;
}
Is it correct since I could not the class now for the time being.
Also since my progressbar is in other form such as Form2, how can I access the progress bar
in this Form2. Could you please help since I have due date on Monday?
Thanks,
JT
So I can use like:
void Adt42To45_FirmwareDownload
{
progressBar.Value = value;
}
Is it correct since I could not the class now for the time being.
Also since my progressbar is in other form such as Form2, how can I access the progress bar
in this Form2. Could you please help since I have due date on Monday?
Thanks,
JT
Is this the same question as you've asked on the Background Thread?
ASKER
Hi dimai,
Yes. it is correct.
JT
Yes. it is correct.
JT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks,
JT
JT
You can get more info on this here: http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx
That page has a good example on how to create and subscribe to an event.
Hope this helps.