Monday, May 19, 2008
How to Create a Transparent User Control in .NET
Thankfully there was a post from Zhi-Xin Ye of Microsoft on the MSDN Windows Forms Forums, in which he outlines how to "roll yer own" transparent UserControl:
Transparent User Control
Wednesday, May 7, 2008
echominder: a home run from Intuit (and it's free!)
One of the coolest services that has come out of their research group is Echominder:
echominder
Here's a description from the echominder site of how the service works:
scenarioI had actually been using a similar system before signing up for echominder: I'd call my voice mail at work to remind me to do certain things, but I would have to actually be in the office and then log into my voice mail to get the message.
you've got a flight tomorrow and just remembered you need to pick up your dry cleaning and set your out of office message. you're driving to work and can't stop to write it down, but echominder is in your speed dial:
- as you're driving home, call echominder and instruct it to have your cell phone ring at 4:30pm with a reminder to pick-up the dry cleaning.
- leave another message to call you at 8:00am tomorrow morning to remind you to turn on your out of office message on your computer before you shut down and leave for the airport.
- your phone rings right on time and you get the important things done.
Now that I've used echominder a few times, I've found it to be invaluable since it takes out the variables that caused my older methodology to break down:
- Location: I don't have to be in the office, because echominder calls me wherever I am.
- Timing: echominder calls me at the time I specify; I don't have to get a message and then remember to act on it at a particular time, or enter it into Outlook to remind me.
Friday, May 2, 2008
Visual Studio .NET Tip: Setting Tab Order
Thankfully there is a pretty slick way to do it, and I never would have guessed that it was there, but sure enough there was an MSDN Magazine "Advanced Basics" article on the subject back in 2002:
Advanced Basics: Visual Studio .NET: Setting Tab Order, Loading the Toolbox with an Add-in
Thankfully, they didn't change it. It's still there, and here's the procedure:
To set the tab order, you simply select [the controls on which you wish to change the tab order], then select Tab Order from the View menu. Then just click the controls in the order you want the tabs to sit. As you click each control, the tab order will be displayed on the control to keep you up to date. Press Esc when you're finished.
The good news is that this feature is still present in Visual Studio 2008 for Windows Forms, but I'm not sure about the WPF editor, though... hopefully it's still present.
Kudos to Matthew MacDonald for "Pro .NET 2.0 Windows Forms and Custom Controls in C#" book!

This book has already paid for itself in just a couple of weeks -- due to the time saved in trying to find the information I need. Every time I have a question regarding an issue in Windows Forms or with Custom & User Controls, I can find it here. Additionally, the content is written in a manner that can be understood by mere mortals, with some good tips and tricks thrown in too.
Highly recommended.
On the merits of this text, I've already purchased Matthew MacDonald's WPF book (the 3.0 one, since I haven't *quite* moved to VS 2008 yet...).
Thursday, May 1, 2008
XBAP First Glance...
ActiveX Document Redux?
I had read about them in the context of ClickOnce deployment, which may ultimately be a great way to deploy desktop apps through the browser, but XBAP is a relative newcomer. I say relative, because, as Scott Hanselman points out, this smells a lot like ActiveX Documents, with the exception that XBAPs do run in Firefox (but not on FF Mac/Linux unless the Mono guys can crack that nut).
Turning The Pages 2.0: a Live XBAP Example
Anyway, I was really impressed by an amazing example of an XBAP in the application created by the British Library:
Turning The Pages 2.0
http://www.bl.uk/ttp2/ttp1.html
Just this morning I was zooming in on a hand-written copy of Jane Austen's "History of England" (which she wrote when she was 13!), and the experience was a little surreal, as was viewing and turning the pages of Leonardo Da Vinci's Codex Arundel. It felt a little like turning the pages of the books in Myst game series, except these are real books.
Please note that this is not Silverlight (formerly known as WPF/E), this is an actual, full-blown .NET WPF application running in your browser, and the system requirements are commensurate with those technologies.
It's certainly worth checking out, but I'm a little skeptical that this is the next big thing in application deployment (just try clicking the back button in your browser when running the application). The requirements may be a little heavy too, but it definitely opens up some new doors, and machines will hopefully keep up with the demands of these new flavors of applications (WPF, XBPAP, etc.).
Additional References:
Monday, April 28, 2008
Remember to set SynchronizingObject property for System.Timers.Timer objects in .NET WinForms
I'm currently building a cool animated window, and instead of using the drag-n-drop timer for WinForms I wanted to just use a timer in code (in this case System.Timers.Timer), since I need it to go into a couple of modes, and it just seemed more straightforward since all my code related to the timer could be just in my .cs file, and not spread across the .Designer.cs and the .cs files.
When I tried to set a property on the form from the event handler I had set up that responded to the Timer's Elapsed event, I was getting a nasty "Control control name accessed from a thread other than the thread it was created on" error.
After scanning the help documentation (see the MSDN Help Link), it turns out that when using a timer with a form, it's advisable to set the SynchronizingObject property to the form object to prevent the aforementioned threading error:
If you use the Timer with a user interface element, such as a form or control, assign the form or control that contains the Timer to the SynchronizingObject property, so that the event is marshaled to the user interface thread.
The good news is that after setting the SynchronizingObject to the form object, the threading issues went away and the form started to behave correctly!
Tuesday, April 22, 2008
Extract Superclass Refactoring on UserControl
- How do you perform an "Extract Superclass" on an existing UserControl in .NET?
I then posted this question on the MSDN Forums.
Honestly, I was hoping that there would be a tool for doing this, or at least a documented process. No such luck.
So, I went ahead and did my best to perform the refactoring, all the while documenting the procedure.
To summarize, here are the steps:
As promised, here's an oversimplified list of the things I did to accomplish this:
Created a new UserControl to use as the base (let's just call it "BaseUserControl"). Moved private member variables, event handlers, and other methods pertinent to the functionality I wanted up into BaseUserControl. Copied control(s) I needed from OriginalUserControl into the BaseUserControl using the visual designer (it's just easier that way, plus resources are managed correctly). Hooked up BaseUserControl events to the event handlers using the visual designer (again, it was just easier). Commented out duplicate code in OriginalUserControl (i.e. the methods, etc. that were moved up) Changed the inheritance of OriginalUserControl from UserControl to BaseUserControl. Build, fix, build......and it worked! Now I can build a NewUserControl based on BaseUserControl and it will have all the functionality that I was wanting in the container, but I can still add more controls, etc. specific to each case I need it.
I just wanted to mention again why I wanted to do this in the first place, since it may seem weird to go through all this:
- First, I created a pretty useful control for a project I was working on, but didn't think about reuse (oops!).
- Naturally, it became apparent that I would need another similar component after the initial proof-of-concept was done.
- After determining that the functionality of the container could be used in other controls, I needed a way to pull that functionality up so that I could use inheritance to create new user controls based on the container.
Actually it wasn't as bad as I thought, though it sure would be nice if this was an automated process, or at least if there was a documented step-by-step how to on the subject.
At any rate, I sincerely hope this helps other developers faced with a similar challenge!
