(continued)
Environment: Visual Studio .NET, managed C++, C#, Visual Basic
In one of the applications I have created is a "Send To" menu class using MFC, which displays a list of the user's "Send To" extensions and sends a file to the extension the user selects. Now, I tried to write a Microsoft .NET assembly and I chose the "Send To" menu class as stuff for the assembly.
WARNING: The assembly source code may contain errors. Use the source code of the assembly at your own risk.
Visually, the "Send To" menu is a menu containing menu sub-items with the graphical representation of the user's "Send To" extensions. The sub-items can be both with and without bitmaps.
The "Send To" menu class is a descendant of the System.Windows.Forms.MenuItem class and contains the following new public properties and methods:
public bool EnableBitmap [ get, set ]
public void Replace ( System.Windows.Forms.MenuItem menuItem,
System.EventHandler eventHandler )
public void Restore ( )
' [Visual Basic]
Public Property EnableBitmap As Boolean
Public Sub Replace(ByVal menuItem As System.Windows.Forms.MenuItem, _
ByVal eventHandler As System.EventHandler)
Public Sub Restore()
 | EnableBitmap |
Gets or sets a value indicating whether the subitems have bitmaps |
 | Replace |
Replaces an existing menu item by a Send To menu item |
 | Restore |
Restores the menu item which is replaced by the Replace method |
You can use the given class in two ways. The first one is to replace an existing menu item and the second one is to add a new "Send To" menu item to the application menu manually. Use the first method if you design an application menu using the designer, and the second one if you create an application menu manually.
To replace an existing menu item you have to perform the following steps:
Declare a form variable based on the SentToMenuItem class.
private megaBYTE.SendToMenuItem menuItemSendTo;
' [Visual Basic]
Friend WithEvents MenuItemSendTo As megaBYTE.SendToMenuItem
-
Create an instance of the SentToMenuItem class.
menuItemSendTo = new megaBYTE.SendToMenuItem();
Me.MenuItemSendTo = New megaBYTE.SendToMenuItem()
-
If it is necessary, set the EnableBitmap property.
menuItemSendTo.EnableBitmap = false;
' [Visual Basic]
Me.MenuItemSendTo.EnableBitmap = False
-
Call the Replace method.
menuItemSendTo.Replace(menuItemSendToStub,
new EventHandler(menuItemSendToStub_Click));
' [Visual Basic]
Me.MenuItemSendTo.Replace(Me.MenuItemSendToStub, _
New EventHandler(AddressOf Me.MenuItemSendToStub_Click))