views:

174

answers:

3

Hello fellow developers,

I'm currently developing a WinForms application in C#, and need some input on how to manage toolbar buttons, menus and other context sensitive elements. What is the best practice for this?

I've found the article 'Use Design Patterns to Simplify the Relationship Between Menus and Form Elements in .NET' on MSDN but I'm not sure if there is a better way since the article is pretty old (it's published in 2002).

Grateful for any constructive help.

+1  A: 

When developing an event-intensive application (lots of menus, toolbars in lots of forms) it is common to have certain events overlap or repeat, in the sense that there are many ways to do a certain thing, and I see this redundancy as a benefit to the user, but a bane to the developer.

A well planned object-oriented approach will dictate how to manage the actions triggered by events so as to avoid duplicate or overlapping code.

Joey
A: 

You could of course find a very useful source of inspiration in Microsoft Office, as it is somewhere a standard (THE standard?).

Depending on the kind of form you are using, I guess you could set some basic rules, where for example data entry forms will have a basic menu such as validate\quit\refresh\abandon\print\export to excel\filter\order by\etc. Such menus (let's call them "Standard") will be ideally available under the "File" and\or "Edit" and\or "View" menu controls, sticking to standard Office menus (even Firefox uses this terminology).

I'd advise you to allways display this standard menus, even if some of the actions are not allways available for such or such forms. Just imagine that data contained in one of your forms cannot be updated under certain circumstances: you can still display the disabled version of the "validate" icon instead of making it invisible. This will definitely make things easier to understand for the final user.

Once this standard list of menus/options established, I guess you'll come up identifying 2 other major "menus" families, the "Details" menus and the "Actions" menus:

  • Details menus allow you to navigate through forms, accessing/displaying subforms/subsets of data, such as Items in a Purchase Order.
  • Action menus allow you to run specific actions on the data, such as emitting a purchase order.

Your different menus shall be made available through a command bar, and context sensitive shortcuts. Options such as "filter" can be made available at the bound control level, while actions such as "Emit the PO" are only available at the record/form level.

People, or group of people, shall then be allowed or not to open forms and/or to run specific actions on these forms

In order to manage menus and rights, our apps have a default "menu file" on the client side, and both a "userGroup-forms" and "userGroup-actions" tables on the server side.

  • userGroup-forms table links groups and forms and list view\modify rights of each group.
  • userGroup-actions table contains a true value when a group has the right to perform a specific action

When connecting to the database, the user is identified and its local menu file is updated to give him corresponding view/action rights.

We are clearly here in an object oriented approach, aren't we?

Philippe Grondier
Ms Office is NOT the standard. It's just one of many approaches to managing the complexity of menus.
Chuck Conway
As most people use Word and Ecel, we could say they have deeply influenced the way people interact with a software. So it's allways a good start to see "how people think". I am not saying in any way that we have to follow Microsoft rules ...
Philippe Grondier
By the way these "standard menu rules" might be older than the Office Software suite itself!
Philippe Grondier
A: 

The ToolStripManager class has a Merge Method, so you could have any child Forms/User Controls expose their own ToolStrips that get merged with your main form's tool strip when they have focus.

http://msdn.microsoft.com/en-us/library/5523fet0.aspx

If you are using MDI, you can also merge menu items of parent and child forms.

http://msdn.microsoft.com/en-us/library/ms404319%28VS.80%29.aspx

OG