Click here to Skip to main content
15,884,176 members
Articles / Programming Languages / C#
Article

Dynamic MainMenu formation in Winform Application using XML

Rate me:
Please Sign up or sign in to vote.
2.82/5 (11 votes)
4 Feb 2004 59.1K   1.7K   20   7
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.<v:shapetype coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> 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!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Amalorpavanathan Yagulasamy (AMAL) is a Software Engineer for Protech Solution Inc. and has designed and implemented projects for Arkansas Child Support, Arkansas Budgetting, Michigan Child Support , Massachusetts Child Support, National Informatics Center-India and Indian Oil Corporation. His background is in developing relational databases and n-tier applications on Windows platforms in CMM Level Standards. He can be reached at amal_forum@hotmail.com

Comments and Discussions

 
GeneralYes,Very Useful... Pin
chinesedragon4-Dec-09 14:30
chinesedragon4-Dec-09 14:30 
GeneralThank you Pin
vmo3d13-Sep-06 5:54
vmo3d13-Sep-06 5:54 
GeneralDynamic Event Handling Pin
Aekeh28-Jul-06 4:05
Aekeh28-Jul-06 4:05 
QuestionXML used poorly? Pin
dog_spawn6-Feb-04 8:45
dog_spawn6-Feb-04 8:45 
I think it is bad form to use the tag name for the title of menu items. It isn't really proper use of XML as you would have a hard time validating against an XSD.

You could improve this article by using XML in a validation compatible way, explaining why we would want to do this in the first place and finally how other types of controls can be defined in XML. I suppose it would also be worth your while to improve the way events are attached to the menu items.

I hope you understand what I mean! Good luck btw.

I'm sure there is already a really good article about creating Windows forms from XML at code project. I can't find it now D'Oh! | :doh: Maybe it was ASP.NET? Big Grin | :-D
AnswerRe: XML used poorly? Pin
Amalorpavanathan Yagulasamy(AMAL)6-Feb-04 18:36
Amalorpavanathan Yagulasamy(AMAL)6-Feb-04 18:36 
GeneralImages still pointing to local files Pin
partyganger28-Jan-04 20:28
partyganger28-Jan-04 20:28 
GeneralRe: Images still pointing to local files Pin
Amalorpavanathan Yagulasamy(AMAL)29-Jan-04 3:49
Amalorpavanathan Yagulasamy(AMAL)29-Jan-04 3:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.