Click here to Skip to main content
6,291,522 members and growing! (15,180 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate

A managed "Send To" menu class

By Alexey Sinutin

An article on a small managed C++ class which gives ability to use the "Send To" feature of Windows Explorer.
C#, VB, VC7, Windows, .NET 1.0, Dev
Posted:20 May 2002
Views:47,413
Bookmarked:23 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
5 votes for this article.
Popularity: 2.52 Rating: 3.60 out of 5
1 vote, 50.0%
1

2

3

4
1 vote, 50.0%
5

Sample Image

Introduction

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:

// [C#] 

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:

  1. Declare a form variable based on the SentToMenuItem class.

    // [C#]
    
    private megaBYTE.SendToMenuItem menuItemSendTo;
    ' [Visual Basic] 
    
    Friend WithEvents MenuItemSendTo As megaBYTE.SendToMenuItem
  2. Create an instance of the SentToMenuItem class.

    // [C#]
    
    menuItemSendTo = new megaBYTE.SendToMenuItem();
    ' [Visual Basic] 
    
    Me.MenuItemSendTo = New megaBYTE.SendToMenuItem()
  3. If it is necessary set the EnableBitmap property.

    // [C#]
    
    menuItemSendTo.EnableBitmap = false;
    ' [Visual Basic] 
    
    Me.MenuItemSendTo.EnableBitmap = False
  4. Call the Replace method.

    // [C#]
    
    menuItemSendTo.Replace(menuItemSendToStub, new EventHandler(menuItemSendToStub_Click));
    ' [Visual Basic] 
    
    Me.MenuItemSendTo.Replace(Me.MenuItemSendToStub, _
                             New EventHandler(AddressOf Me.MenuItemSendToStub_Click))

The most interesting is point 4. The first parameter of the Replace method is the item to be replaced and the second parameter is a new instance of the EventHandler class. The parameter of the EventHandler class constructor is the click event handler of the replaced item. The click event handler method looks like

// [C#]

private void menuItemSendToStub_Click(object sender, System.EventArgs e)
{
  if (e.GetType() == typeof(megaBYTE.SendToClickEventArgs)) 
  {
    OpenFileDialog dlg = new OpenFileDialog();
    dlg.CheckFileExists = true;
    if (dlg.ShowDialog() == DialogResult.OK)
    {
      megaBYTE.SendToClickEventArgs se = (megaBYTE.SendToClickEventArgs)e;
      se.FileName = dlg.FileName;
    }
  }
}
' [Visual Basic] 

Private Sub MenuItemSendToStub_Click(ByVal sender As System.Object, _
                 ByVal e As System.EventArgs) Handles MenuItemSendToStub.Click
  If TypeOf e Is megaBYTE.SendToClickEventArgs Then
    Dim dlg As New OpenFileDialog()
    dlg.CheckFileExists = True
    If dlg.ShowDialog = DialogResult.OK Then
      Dim se As megaBYTE.SendToClickEventArgs
      se = CType(e, megaBYTE.SendToClickEventArgs)
      se.FileName = dlg.FileName
    End If
  End If
End Sub

If you are going to add the "Sent To" menu manually just use the SendToMenuItem class as the System.Windows.Forms.MenuItem class.

The assembly source code contains parts of the Microsoft SENDTO sample.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Alexey Sinutin


Member

Location: Russian Federation Russian Federation

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
GeneralMonitor Send to Command Pinmembereg_Anubhava19:46 5 May '09  
Generali need to send to menu class Pinmembersyriast3:19 2 Aug '06  
GeneralRe: i need to send to menu class Pinmembersyriast0:29 3 Aug '06  
GeneralPorting to ToolStripMenuItem Pinmembernhlpens669:34 3 Jul '06  
GeneralWrite a "Send To" menu class in c# Pinmemberlin116119:36 8 Aug '05  
GeneralCode Explanation PinmemberChris Keeble0:25 27 Apr '05  
Generalsendto - mail PinsussyarivNachmias18:50 14 Nov '04  
GeneralNice :-) PinmemberNish - Native CPian19:50 21 May '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 20 May 2002
Editor: Chris Maunder
Copyright 2002 by Alexey Sinutin
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project