
Typically when we write our code, the event handlers get wired up for us using the handles clause. So we never have to worry about wiring up our event handlers manually.
But what about the case where we want to dynamically add a control to our Windows Form or our ASP.NET page? For example, add a button. How would you respond to the button click event?
In CSharp, there is no handles clause, so figuring out how to manually wire up the event handler is simply a matter of inspecting the dotNet code and doing a copy/paste/modify operation in the editor.
The syntax for adding event handlers manually is not that difficult.
1 | AddHandler m_button.Click, AddressOf buttonClickMethod |
If you’ve written any threading code, you’ll notice that this looks similar to the code you might have written for that.
The AddHandler statement takes two parameters. The first is the event we are going to handle–in this case, the click event from the object that m_button is pointing to.
The second parameter is a pointer to a function that will handle the event. What is unique about this is that it can be a method that is part of the current class, which is what the code above is referencing, or it can be a method in another object, or even a method that is shared in another class.
To reference a method in another object
1 | AddHandler m_button.Click, _ |
To reference a shared method
1 | AddHandler m_button.Click, _ |
Which gives us quite a bit of flexibility when we dynamically wire up our events.




When I first started generating PDFs dynamically, I was overwhelmed by the complexity of the API. Not just with iTextSharp, but it seemed that all of the APIs were complex. In looking through the API and comparing it to what I was actually trying to accomplish, I found there was a very small subset of classes and methods that I needed to use to accomplish the task at hand. Now that I’ve learned more, I still use this same subset of commands for 90% of what I need to do in iTextSharp. The reason we produce PDFs programmatically at all is because we need to dynamically generate some information on the page. Most of the time, this information comes out of a database and gets placed on the same location of the page each time the page is generated. The rest of the information is static. So what I normally do is have my designer or project manager create a PDF for me with form fields located where he wants the information to go. Using the form fields, he can define the font, size, color, and position he wants to display the text with. All I have to worry about is getting the text into the field. This works out nicely because once I’ve filled in the forms, he can move them around until he’s happy with them without asking for my help. We’ve already covered
There are several libraries on the market now that allow you to create PDF documents from your .NET applications. The one I’ve chosen to use is
On Monday, I was corrected in my assertion that creating multiple empty strings would create multiple objects. Turns out the compiler automatically puts all of the strings that are exactly the same in a “string pool” so that there is only ever one empty string in the entire application you’ve created.
I recently read an article that argued that “” is “Better than String.Empty”
I just read a post by Casademora on “public abstract string[] Blog()”