|
|
hi, i'm totally flabberghasted by the event model, at least for what i want to do which is to copy the event delegate (as part of copying a template control).
the short story is, copying the event delegate works no problem from within the scope of the class which defines the event, but the compiler does not let you do it from outside the class-- similar to the behavior of a field marked "private", although the event is clearly public.
can anybody clue me into the rhyme or reason of this behavior? it presumably is related to the "non-field" implemplementations of events using add and remove, but i still don't understand why the support isnt there for me to determine how events were implemented in the class and clone them from one instance to another.
thanks in advance! here's the snippet:
<br />
public class Bar <br />
{<br />
public event EventHandler BarEvent; <br />
}<br />
<br />
public class Foo <br />
{<br />
public event EventHandler MyEvent; <br />
Foo foo; <br />
Bar bar, foobar; <br />
<br />
this.MyEvent = foo.MyEvent;
foo.MyEvent = this.MyEvent;
bar.BarEvent = foobar.BarEvent;
}<br />
|
|
|
|
|
You should check-out MSDN for this: http://msdn.microsoft.com/library/en-us/cpguide/html/cpconevents.asp[^]
Essentially, as is common in COM and other platforms as well, think of an event as a collection of delegates (managed function pointers). For this reason, you use incremental (+=) and decremental (-=) assignment operators like all the examples use in the .NET Framework SDK documentation.
You can't directly assign (=) your event handler to another class's event. That's why your getting the compiler error when you're doing it to another class and not your own (this). You should be doing it to your own event anyway. Events are actually based on MulticastDelegate derivatives, because when you use the delegate keyword, it will actually derive from MulticastDelegate . See the docs for details.
In comparison, you can use delegates as callback functions throughout your app, but events really aren't callbacks. As I said before, they're more like a collection of callbacks.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
How can I repait the Caption area of a window customized? I can't get the graphics of caption area.
|
|
|
|
|
You have to get low-level, and deal with Windows API calls and messages, like WM_NCPAINT. Plus, you'll have to fight w/ some painting anomalies. In short, it's no fun.
|
|
|
|
|
|
Check-out this article on MSDN that uses BITS (only with Win2K, WinXP and newer, but could be written using a standard WebRequest ).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
If I have loaded a dll in my program, how can I free it?
Andyniyong waiting for your answer.
|
|
|
|
|
You can't.
To unload a dll, you must load it in a separate application domain, so when you unload your second application domain, the dll will also unload...
Free your mind...
|
|
|
|
|
Hi, All
I do have two questions :
1.) Is there any possibility to derive a class from the component class and drag it into a form (like a usercontrol)?
2.) If so i wonder is someone have build some kind of GraphicalUserComponent class, a class wihout a window handle.
(define Email (lambda ()
elacroix@devmesh.com))
Im not a church numeral im a free variable
|
|
|
|
|
Regards everybuddy,
Except timer method, how can I monitor a variable (for example a string) and call a method as soon as and each time it changes?
Thanks for any note and best wishes
-nSun
---
"Art happens when you least expect it"
|
|
|
|
|
I don't think you can attach an event to a variable in C#.
Of course you can theoritically create your own variable class which raises an event everytime it is changed.
However, I probably will just create a property for the variable which will call a method every time it is set.
Create your class if you need to use many variables, otherwise create a property.
Hope it helps.
|
|
|
|
|
Yes, Propert method is greate but in some cases creating a new class will be more effective. Thanks buddy
---
"Art happens when you least expect it"
|
|
|
|
|
Yes, Property method is greate but in some cases creating a new class will be more effective. Thanks buddy
---
"Art happens when you least expect it"
|
|
|
|
|
did you try making it a property (with get & set accessors that you can put whatever code you want into) or is that not suitable for what you want to do?
|
|
|
|
|
It seems it is the best choice in many cases. Thank you for your comment allancto.
---
"Art happens when you least expect it"
|
|
|
|
|
do someone know any Decompiler witch can decompile all dll files for c#?
thank u for help
|
|
|
|
|
|
Hey, I didn't know it did decompilation also! I oughta take a look, as Anakrino doesn't work on Win98, and Reflector might.
|
|
|
|
|
And it works! Thanks Nick!
|
|
|
|
|
NP Maybe it will speed development of the FLUID UI Toolkit?
-Nick Parker
DeveloperNotes.com
|
|
|
|
|
|
I need a horizontal tree control that would look like all the trees one sees in data structures textbooks, but have all the usual functionality (check boxes, drag/drop, etc.) Does such a thing exist?
The root would be center/top. Nodes would grow down to the left or right. Leaves would all be at the bottom.
How hard would it be to convert a std tree control into a horizontal one?
|
|
|
|
|
It would be very hard - and probably incredibly stupid - to make the "standard" tree control do such a thing. First of all, the .NET tree control is actually the SysTreeView32 common control in Windows, wrapped in a class for easy use with .NET. With this in mind, you have to go very low-level to change such behavior.
Since you're changing so much, however, it'd be much easier to do this from scratch in a completely managed solution. What you're describing, however, is common in organization charts. You could try searching for an existing organization chart control in .NET, which may help in constructing a more generic tree with the behavior you want. I can't think of any off-hand, but I'm willing to bet there's a few around - perhaps even here on CodeProject.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
That's an excellent tip. Thanks!
Dave
|
|
|
|