65.9K
CodeProject is changing. Read more.
Home

Dynamic MainMenu formation in Winform Application using XML

Jan 28, 2004

viewsIcon

59762

downloadIcon

1738

Dynamic MainMenu formation in Winform Application using XML

Introduction

If our Winform application is having Menu level security, we can build the Main menu using XML in following way.

Building Menu

Like ASP.Net Tree control, we can build the Main menu using XML in runtime. For that i have created three methods,
CreateMenu
CreateMenuItem
CreateMenuItems
and one event.
Menu_Click

Here the method CreateMenu is used to create all menu items by using CreateMenuItem and CreateMenuItems.
CreateMenuItem is used to create Top level menuitems and CreateMenuItems is used to create all child level menuitems. The following figure shown the XML file format.

XML

CreateMenuItems is a recursive method, so you can include n-level menuitems.

Code

The menu will be shown like,

Menu Design

And Menu_Click event is used to configure the all menu item events.

Menu Event

Finally

I think this shows how you can implement the security in MainMenu and any help, comments are much appreciated!