Add Localized Menu Items

[Top]  [Chapter]  [Previous]  [Next]


The GUI definition file of TextDynamic contains the localization of the dialog strings and also action captions and hints. Some action names have been reserved to store the caption for menu drop downs only.


This enum definition can be used for code which creates a menu in code:



internal enum wpaMenuCaps














Using this action names and a selection of the 'intelligent' actions you can create a framwork to create the menu of your form "on the fly".


We created a menu class which handles the update of the strings completely automatically.


You only need to to implement the IGetCurrEditor interface in your winform.


public class WinForm : System.Windows.Forms.Form,IGetCurrEditor


  public WPDynamic.WPDLLInt CurrEdit()  { return wpdllInt1; }




Now you can create the procedure which creates the menu. The actions for each menu drop down are provided as string array. This makes this code easy to be updated (green lines).


private void UpdateMenu(System.Windows.Forms.MainMenu menu, wpaMenuCaps selection)


 // Select the items for the menus - implemented as array of string array

 string[][] wpaMenuItems = new string[10][];

 // DropDownMenuFile

 wpaMenuItems[0]= new string[]


 // DropDownMenuEdit

 wpaMenuItems[1]= new string[]


 // DropDownMenuView

 wpaMenuItems[2]= new string[]

 {"DiaManageHeaderFooter","ShowCR","-", "LayoutNormal",

                         "zoom100", "zoomwidth", "zoomfullpage", "zoomdoublepage" };

 // DropDownMenuInsert

 wpaMenuItems[3]= new string[]

 {"DiaINSGRAPHIC", "DiaINSSymbol", "DiaINSHyperlink", "DiaINSFields"};

 // DropDownMenuFormat

 wpaMenuItems[4]= new string[]

 {"DiaParagraphProp", "DiaParagraphBorder", "DiaBulletOutlines"};

 // DropDownMenuExtra

 wpaMenuItems[5]= new string[]

 {"DiaSpellcheck", "DiaSpellOptions", "SpellAsYouGo"};

 // DropDownMenuData

 wpaMenuItems[6]= new string[]


 // DropDownMenuTable

 wpaMenuItems[7]= new string[]

 {"DiaINSTable", "DiaParagraphBorder",

         "InsColBefore","InsCol", "InsRowBefore", "InsRow"};

 // DropDownMenuWindow

 wpaMenuItems[8]= new string[]


 // DropDownMenuInfo

 wpaMenuItems[9]= new string[]


 // ----------------------------------------------------------------

 string[] wpaMenuCapsNames = {




                                 "DropDownMenuData", "DropDownMenuTable",

                                 "DropDownMenuWindow", "DropDownMenuInfo"};

 WPDynamic.WPAMenuItem item, pitem;

 for(int m=0, a=1; m<=10;m++,a=a*2)




                            pitem = new WPDynamic.WPAMenuItem(

                                 this, wpaMenuCapsNames[m]);

                            // Now create the menu items

                            foreach(String s in wpaMenuItems[m])


                                   item = new WPDynamic.WPAMenuItem(this,s);









After adding to event Form.Load -


 // Initialize MainMenu

 mainMenu1.MenuItems.Clear(); // Start from scratch!








//        wpaMenuCaps.wpaDropDownMenuData|


//        wpaMenuCaps.wpaDropDownMenuWindow|

 wpaMenuCaps.wpaDropDownMenuInfo );



this is how the menu will look at runtime.







[addlocalizedmenuitems.htm]    Copyright © 2007 by WPCubed GmbH