This is VB but you should have no issue applying the principle to C#.

http://www.vbforums.com/showthread.php?t=454466