Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis based on XML Module Integration Framework

Shulou Source: shulou.com Published: 2022-06-03 11:55:33 11月15日 Update

< node.ChildNodes.Count - 1;i++ ) { child1 = node.ChildNodes[i]; //检查是否提供了类型 asmname = child1.Attributes["AssemblyName"].Value; formtag = child1.Attributes["FormTag"].Value; text = child1.Attributes["Name"].Value; OfficeMenuItem childitem; childitem = new OfficeMenuItem(true, text, handler); childitem.Name = text; mc = new MenuClass(); mc.Assemblyname = asmname; mc.FormTag = formtag; childitem.Tag = mc; //添加快捷键 msc = child1.Attributes["ShortCut"].Value; if(msc != string.Empty) { childitem.Shortcut = MenuShortCut.GetShortCut(msc); } //添加图标 iconname = child1.Attributes["Image"].Value; if(iconname != string.Empty) { iconpath = Themes.GetCurrentThemePath() + iconname; childitem.IconPath = iconpath; } parent.MenuItems.Add(childitem); if((iconpath != string.Empty) && System.IO.File.Exists(iconpath)) { //添加按钮到OutlookBar PanelIcon picon = ip.AddIcon(childitem.Text, Image.FromFile(iconpath), handler1); picon.Tag = mc; //添加按钮到toolbar ToolStripButton button = new ToolStripButton(childitem.Text, Image.FromFile(iconpath), handler2); button.DisplayStyle = ToolStripItemDisplayStyle.Image; button.ToolTipText = childitem.Text; button.Tag = mc; button.Visible = true; _toolbar.Items.Add(button); } iconpath = ""; mc = null; if(child1.ChildNodes.Count >

0) {GetChildMenu (ip,childitem, child1) } / * * / Open a combination of form / form class assembly and form class, and get private void OpenForm (MenuClass mc) {string asmname = mc.Assemblyname; string formtag = mc.FormTag from the AssemblyName property of the node. If (formtag = = "") {throw new Exception (Resources.StringNoFormFlag);} if (formtag.ToUpper () = = "TRUE") {if (asmname = = string.Empty) {throw new NullReferenceException (Resources.StringAssemblyNull) } / / string [] a = asmname.Split (','); object obj = null; Type tp = Type.GetType (asmname); if (tp! = null) {obj = Activator.CreateInstance (tp) } else {throw new Exception ("an error occurred while loading the program, please check whether the program (dll,exe) exists or is of the correct type.") ;} / / check whether it is Form class if ((obj = = null) |! (obj is Form)) {throw new Exception (Resources.StringNotForm);} Form frm = (obj as Form) / / check whether the first window opened is MDIFORM if (Application.OpenForms [0] .IsMdiContainer) {/ / as MDICHILDFORM frm.MdiParent = Application.OpenForms [0];} / load form frm.Show () }} / * / menu Click event / private void OnPluginClick (object sender, EventArgs args) {OfficeMenuItem item = (OfficeMenuItem) sender; MenuClass mc = (MenuClass) item.Tag If ((item.Text = = "EXIT") | (item.Text = = "EXIT") {OnExitClick (sender, args); return;} OpenForm (mc);}}

Delegate is used in this, and the most important function is to load the menu function and the OnPluginClick function.

Using this framework, you can dynamically add modules at any level.

Microsoft's CAB uses Resigster site to add modules, which is not very convenient.

This is the end of this article on "sample Analysis based on XML Module Integration Framework". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Menus files modules forms nodes validation frames functions time programs articles checks examples analysis more errors preparation good practical important Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft OPPO Reno Shulou Tech Info NVidia