This is my article on how to eliminate those long switch statements:
Dynamic Method Dispatcher, No more long switch statements!
In your case, it could be even simpler: you could have a dictionary keyed by something, with the value representing the form reference (window reference, page reference, page URL, whatever). If this is not clear, I would need to know more detail (what is entered).
However, you should better remove this apparently bad design with entering something in a text box and create, say, humane menu. And don't create a separate handler of all menu items, use one dispatching a click on a particular item to a corresponding form. You can, for a simple implementation, store form references in item's
Tag
.
For your information, since the times when mainframe computers dominated, Inquisition has virtually ran out of business; sinned people are no longer sentenced for entering mystical codes in text boxes, they are still allowed to use menus, toolbars and other similar tools of humanity.
[EDIT]
Please see also my comment to Solution 2. You can wrap the call to
Form.Show
in the code adding a form instance to the dictionary. First, this code checks up if the reference is already in a dictionary (using
Dictionary.HasValue
), and, if not, adding it. The calculation of the key can be implemented in the form class, say, your base form class.
—SA