tags:

views:

55

answers:

3

Im creating a level editor application designed in a MDI project. The application have to main view modes. WorldEditor mode and ObjectEditor mode. Depending on what type of mode form is active I want a separate property window to show a property setup specific for either world or object mode. For this I've thought of using the 'Activated' event on the world or object form, and from that event tell the property form to load the setup for either world or object. For this I need to reach the PropertyForm from within the World or Object Form class. And thats where I'm stuck...

I belive I should solve this by either declare the Property Form class as static since I only use one of it's type and I want to be able to reach it globaly. But declaring a form class as static gives me compiler errors, so I'm doing it wrong if it's even possible to do.

I assume that there also is an easier way to reach and search for different forms that is active in the application, but how do I do that?

Thanks for any suggestions or feedback Best Regards

A: 

What you need is a singleton, not a static class.

Without much loss of performance you can create different objects of PropertyForm - one for each type of 'view' you have. You can add a parametrized constructor - should take an object that has the details specific to each view. This will allow you to create the PropertyForm specific for each view.

If you really want to have just one copy of the PropertyForm, then a simpler approach is to hide the form. In the "show" event handler you can customize it per the current view. Consider the singleton approach as the last.

Sesh
A: 

Sounds to me like your MDI parent form (which knows which of the MDI child windows is active) should hold a reference to the Property form. Add an event handler to each created child window's Activated event, using a function in your parent form that uses the information from the activated child window to set up the Property form correctly.

Sesh's answer regarding a Singleton may apply as well, though that's really another question.

Harper Shelby
A: 

You may be able to get what you need from the sender parameter in the Activated event handler.

Matt Brunell