13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}}menuTools.MenuItems.Add(<strong>in</strong>dex, mnuItem);<strong>in</strong>dex += 1;The DataSet object that the section handler returns is built from the <strong>XML</strong> code rooted <strong>in</strong>. This code orig<strong>in</strong>ates a DataSet object with one table, named MenuTools.The MenuTools table has three columns: Text, Assembly, and Class. Each row <strong>in</strong> thetable corresponds to a plug-<strong>in</strong> module.The preced<strong>in</strong>g code first adds a separator and then iterates on the rows of the tableand adds menu items to the Tools menu, as shown <strong>in</strong> Figure 15-3. MenuTools is justthe name of the Tools pop-up menu <strong>in</strong> the sample application.Figure 15-3: Registered plug-<strong>in</strong> modules appear on the Tools menu of the application.To handle a click on a menu item <strong>in</strong> a W<strong>in</strong>dows Forms application, you need toassociate an event handler object with the menu item. Visual Studio .<strong>NET</strong> does this <strong>for</strong>you at design time <strong>for</strong> static menu items. For dynamic items, this association must beestablished at run time, as shown here:DynamicMenuItem mnuItem;mnuItem = new DynamicMenuItem(configMenuItem["Text"].ToStr<strong>in</strong>g(),new EventHandler(StdOnClickHandler));A menu item is normally represented by an <strong>in</strong>stance of the MenuItem class. What isthat DynamicMenuItem class all about then? DynamicMenuItem is a user-def<strong>in</strong>ed classthat extends MenuItem with a couple of properties particularly suited <strong>for</strong> menu itemsthat represent calls to plug-<strong>in</strong> modules. Here's the class def<strong>in</strong>ition:public class DynamicMenuItem: MenuItem{public str<strong>in</strong>g AssemblyName;public str<strong>in</strong>g ClassName;public DynamicMenuItem(str<strong>in</strong>g text, EventHandler onClick):base(text, onClick){}}526

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!