Technolithic's picture

Creating Custom Events in C#

Continuing on with my project, after finally getting selection/picking working in OpenGL, I ran into another roadblock. It seems that with the objects that were selected using the picking technique comes the need to do something with those objects outside the object that they were "picked" from.

I've searched on the net and found several sources of information covering the issue, but a clear concept seems to overload my flux capacitors and imprison my mind in a temporal rift that abandons me to slobbering on my keyboard in an involuntary, stupefied hopeless somber.

What I understand is that in order to pass data from a subclass back to the base class, an event must be fired in the subclass to tell the base class to call a method contained in the subclass to return the data back to the base class. This sounds easy to imagine, but the implementation of it uses concepts like delegates, which sounds like a function pointer on steroids, and an event handler, which I've seen plenty but have no practice with them since visual studio takes care of that using the form designer. I have some source code that I've been looking through to try and understand it and implement it in a slightly different way to be used in my app, but like I said I'm lost in the sauce.

Can someone help me out with a "Creating Custom Events for Dummies" online lecture?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Technolithic's picture

Ok, I must be getting better at this stuff, because I was able to figure out how to implement my own solution using some example source code off the net. I don't fully understand it, but from an OOP perspective it makes sense to me.

After my slobber-fest, staring off as if burning a hole through my laptop screen with my Clark Kent laser vision, I was able to reconnect a couple of loose neurons and the power of my brain kicked in. The hamster wheel once again began to squeak, turning the generator for creating the electricity needed to execute a few low-level machine instructions inside my cranium as the rust flung free of the chirping wheel, spinning desperately to barely break a flat-line wave of feeble voltage.

Here's the last several instructions:

Right arm, extend
Grab beer
Swing back mug
Open cake hole
Finish tipping beer back
Empty contents of mug rapidly
Guzzle to prevent drowning
Wait 5 minutes for BAC boost

That's how Custom Events work... any questions?

Inertia's picture
Technolithic's picture

Wow, that eBook has a very nice verbose section on delegates. Thanks, Inertia. It's lot better than the pathetic flatulence that my intro book has for explaining them. I will most likely be enjoying the future implementation of delegates and the like now. You da shizzlin shizzdiggin for rizzle skizzle!

Inertia's picture

It's the best free book I could find so far, have only read some sections of interest tho so cannot really tell if it's overall worth adding to OpenTK's link section. It sure would be good to have something like it among the links.

You da shizzlin shizzdiggin for rizzle skizzle!
Can you please rephrase that? We only learned oxford english at school, not hip-hop slang (kinda sounds like it ;) )

Technolithic's picture

Alright, computer geeks made new computer languages to suit their needs. Can I make up my own "hip-hop-lingo" with a spoken language? The meaning behind it remains deeply ingrained in however one wants to take such goof-ball expressions. Some folks say, "You're the shizznit". Which is like saying, "You are the sh*t", which is a compliment here in the United States, seriously. But shizznit commands a longer title... longer titles in careers denote higher importance on the capitalistic food-chain, which implies a compliment. SO, with, "shizzlin shizzdiggin for rizzle skizzle", I imply a longer title that hopefully conveys the meaning of even higher honors along with an exotic expression of enthusiasm.

Whether or not it makes sense, it does not matter, because I made it up out of thin air and it sounds hippity-hoppity. LOL. I hope you like it.

Inertia's picture

Thanks, I guess :P The title Fiddler got from irc is way cooler and shorter though: "god". Not that creative, but matches his level of awesomeness ;)