I'm a newbie in C# but this seems to me a lot of work to use a generic Click
event method to handle my menu items, which is what I am trying to do. I
don't like that my class code is littered with individual click methods for
similar menu options. Although, I think that what you suggest will work for
me, I may have to do the individual click methods for now. Thanks.
"Bruce Wood" wrote:
// there are 2 forms inheriting from EditorTemplate
// ItemsEditor and CategoriesEditor
public EditorTemplate CreateForm(string inheritedFormName)
{
// EditorTemplate editor; // makes editor in scope, but not
instanstiated.
if (inheritedFormName == "Categories")
editor = new CategoriesEditor();
else if (inheritedFormName == "Items")
editor = new ItemsEditor();
return editor; // IDE says this is not defined within scope.
}
You declare "editor" only once... as an EditorTemplate. Then you assign
either a CategoriesEditor object or an ItemsEditor object to it. Later
on, if you want to know which one it is, you can:
CategoriesEditor catEdit = editor as CategoriesEditor;
if (catEdit != null)
...
or
if (editor is CategoriesEditor)
...
or
CategoriesEditor catEditor = (CategoriesEditor)editor;
The last form throws an exception if editor is not a CategoriesEditor.