c# make barcode // Add dynamic items to existing popup menus 523 in VB.NET

Paint Code 3/9 in VB.NET // Add dynamic items to existing popup menus 523

// Add dynamic items to existing popup menus 523
Code 39 Extended Creator In VB.NET
Using Barcode creation for .NET Control to generate, create Code 3/9 image in .NET framework applications.
www.OnBarcode.com
Recognizing Code 3 Of 9 In Visual Basic .NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
if (configMenu != null) AddMenuToolsPlugIns(configMenu); } The configuration settings that is, the menu items to be added to the Tools menu are read from the configuration file using the ConfigurationSettings class, as usual. Nothing in the preceding code reveals the presence of a custom section handler and a completely custom XML schema for the settings. The only faint clue is the use of a DataSet object. After it has been successfully loaded from the configuration file, the DataSet object is passed to a helper routine, AddMenuToolsPlugIns, which will modify the menu. We'll return to this point in the section "Invoking Plug-In Modules," on page 650; in the meantime, let's review the layout of the configuration file. The XML Layout of the Configuration Settings The data corresponding to plug-in modules is stored in a section group named TypicalWinFormsApp. The actual section is named PlugIns. Each plug-in module is identified by an assembly name, a class name, and display text. The display text constitutes the caption of the menu item, whereas the assembly name and the class name provide for a dynamic method call. As mentioned, in a realworld scenario, you might force the class to implement a particular interface so that it's clear to the calling application which methods are available for the object it is instantiating. Here is a sample configuration file for the application shown in Figure 15-2: <configuration> <configSections> <sectionGroup name="TypicalWinFormsApp"> <section name="PlugIns" type="XmlNet.CS.DatasetSectionHandler, DatasetSectionHandler" /> </sectionGroup> </configSections> <appSettings> <add key="LastLeftTopPosition" value="358,237" /> <add key="LastSize" value="472,203" /> </appSettings> <TypicalWinFormsApp> <PlugIns> <MenuTools> <Text>Add new tool...</Text> <Assembly>MyToolsPlugIns</Assembly> <Class>MyPlugIn.AddNewTool</Class> </MenuTools> <MenuTools> <Text>Special tool...</Text> <Assembly>MyToolsPlugIns</Assembly> <Class>MyPlugIn.SpecialTool</Class> 524
Print Bar Code In VB.NET
Using Barcode encoder for VS .NET Control to generate, create barcode image in .NET applications.
www.OnBarcode.com
Scan Bar Code In VB.NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
</MenuTools> </PlugIns> </TypicalWinFormsApp> </configuration> I deliberately left a few standard application settings (the <appSettings> section) in this listing just to demonstrate that custom sections can happily work side by side with standard system and application settings. In particular, the sample application depicted in Figure 15-2 also supports the same save and restore features described in the section "Using Settings Through Code," on page 634. The <section> element points to the class XmlNet.CS.DatasetSectionHandler, which is declared and implemented in the DatasetSectionHandler assembly. The net effect of this section declaration is that whenever an application asks for a PlugIns section, the preceding section handler is involved, its Create method is called, and a DataSet object is returned. We'll look at the implementation of the section handler in the section "Implementing the DataSet Section Handler," on page 653. Invoking Plug-In Modules The AddMenuToolsPlugIns procedure modifies the application's Tools menu, adding all the items registered in the configuration file. The following code shows how it works: private void AddMenuToolsPlugIns(DataSet ds) { DynamicMenuItem mnuItem; DataTable config; // Get the table that represents the settings for the menu config = ds.Tables["MenuTools"]; if (config == null) return; // Add a separator if (config.Rows.Count >0) menuTools.MenuItems.Add("-"); // Start position for insertions int index = menuTools.MenuItems.Count; // Populate the Tools menu foreach(DataRow configMenuItem in config.Rows) { mnuItem = DynamicMenuItem(configMenuItem["Text"].ToString(), new EventHandler(StdOnClickHandler)); mnuItem.AssemblyName configMenuItem["Assembly"].ToString(); mnuItem.ClassName = configMenuItem["Class"].ToString(); 525 = new
ANSI/AIM Code 39 Generator In Visual C#.NET
Using Barcode creation for VS .NET Control to generate, create Code39 image in Visual Studio .NET applications.
www.OnBarcode.com
Code-39 Printer In VS .NET
Using Barcode encoder for ASP.NET Control to generate, create USS Code 39 image in ASP.NET applications.
www.OnBarcode.com
menuTools.MenuItems.Add(index, mnuItem); index += 1; } } The DataSet object that the section handler returns is built from the XML code rooted in <PlugIns>. This code originates a DataSet object with one table, named MenuTools. The MenuTools table has three columns: Text, Assembly, and Class. Each row in the table corresponds to a plug-in module. The preceding code first adds a separator and then iterates on the rows of the table and adds menu items to the Tools menu, as shown in Figure 15-3. MenuTools is just the name of the Tools pop-up menu in the sample application.
Creating Code-39 In VS .NET
Using Barcode maker for VS .NET Control to generate, create Code 39 Full ASCII image in Visual Studio .NET applications.
www.OnBarcode.com
European Article Number 13 Generator In Visual Basic .NET
Using Barcode maker for .NET framework Control to generate, create European Article Number 13 image in Visual Studio .NET applications.
www.OnBarcode.com
Figure 15-3: Registered plug-in modules appear on the Tools menu of the application. To handle a click on a menu item in a Windows Forms application, you need to associate an event handler object with the menu item. Visual Studio .NET does this for you at design time for static menu items. For dynamic items, this association must be established at run time, as shown here: DynamicMenuItem mnuItem; mnuItem = new DynamicMenuItem( configMenuItem["Text"].ToString(), new EventHandler(StdOnClickHandler)); A menu item is normally represented by an instance of the MenuItem class. What is that DynamicMenuItem class all about then DynamicMenuItem is a user-defined class that extends MenuItem with a couple of properties particularly suited for menu items that represent calls to plug-in modules. Here's the class definition: public class DynamicMenuItem: MenuItem { public string AssemblyName; public string ClassName; public DynamicMenuItem(string text, EventHandler onClick): base(text, onClick) {} }
Draw Barcode In Visual Basic .NET
Using Barcode encoder for .NET Control to generate, create barcode image in .NET framework applications.
www.OnBarcode.com
Code 39 Drawer In VB.NET
Using Barcode drawer for .NET framework Control to generate, create Code39 image in .NET framework applications.
www.OnBarcode.com
The new menu item class stores the name of the assembly and the class to use when clicked. An instance of this class is passed to the event handler procedure through the sender argument, as shown here: private void StdOnClickHandler(object sender, EventArgs e) { // Get the current instance of the dynamic menu item DynamicMenuItem mnuItem = (DynamicMenuItem) sender; // Display corresponding a message box that proves we know the
EAN / UCC - 13 Generator In Visual Basic .NET
Using Barcode generator for VS .NET Control to generate, create EAN 128 image in .NET applications.
www.OnBarcode.com
British Royal Mail 4-State Customer Code Drawer In VB.NET
Using Barcode creator for Visual Studio .NET Control to generate, create RM4SCC image in VS .NET applications.
www.OnBarcode.com
// assembly and class name string msg = "Execute a method on class [{0}] from assembly [{1}]"; msg = String.Format(msg, mnuItem.AssemblyName); MessageBox.Show(msg, mnuItem.Text); } In a real-world context, you can use the assembly and class information to dynamically create an instance of the class using the Activator object that we encountered in 12, as follows: // Assuming that the class implements the IAppPlugIn interface // asm is the assembly name, cls is the class name IAppPlugIn o cls).Unwrap() = (IAppPlugIn) Activator.CreateInstance(asm, mnuItem.ClassName,
ECC200 Generation In .NET Framework
Using Barcode creation for VS .NET Control to generate, create Data Matrix image in .NET applications.
www.OnBarcode.com
Draw Bar Code In .NET
Using Barcode drawer for Reporting Service Control to generate, create barcode image in Reporting Service applications.
www.OnBarcode.com
// Assume that the IAppPlugIn interface has a method Execute() o.Execute(); Figure 15-4 shows the message box that appears when you click a custom menu item in the sample application. All the information displayed is read from the configuration file.
Code-39 Generation In None
Using Barcode maker for Software Control to generate, create USS Code 39 image in Software applications.
www.OnBarcode.com
Encoding Code 39 In Java
Using Barcode drawer for Java Control to generate, create USS Code 39 image in Java applications.
www.OnBarcode.com
Making PDF-417 2d Barcode In Java
Using Barcode printer for Android Control to generate, create PDF417 image in Android applications.
www.OnBarcode.com
Drawing Data Matrix ECC200 In None
Using Barcode printer for Online Control to generate, create Data Matrix ECC200 image in Online applications.
www.OnBarcode.com
Painting PDF417 In None
Using Barcode creation for Font Control to generate, create PDF-417 2d barcode image in Font applications.
www.OnBarcode.com
Code 3 Of 9 Scanner In VB.NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Copyright © OnBarcode.com . All rights reserved.