Torna al Thread

''' <summary> ''' The CountLinesExtensions is an example shell context menu extension, ''' implemented with SharpShell. It adds the command 'Count Lines' to text ''' files. ''' </summary> <ComVisible(True)> _ <COMServerAssociation(AssociationType.ClassOfExtension, ".txt")> _ Public Class CountLinesExtension Inherits SharpContextMenu ''' <summary> ''' Determines whether this instance can a shell ''' context show menu, given the specified selected file list. ''' </summary> ''' <returns> ''' <c>true</c> if this instance should show a shell context ''' menu for the specified file list; otherwise, <c>false</c>. ''' </returns> Protected Overrides Function CanShowMenu() As Boolean ' We always show the menu. Return True End Function ''' <summary> ''' Creates the context menu. This can be a single menu item or a tree of them. ''' </summary> ''' <returns> ''' The context menu for the shell context menu. ''' </returns> Protected Overrides Function CreateMenu() As ContextMenuStrip ' Create the menu strip. Dim menu = New ContextMenuStrip() ' Create a 'count lines' item. Dim itemCountLines = New ToolStripMenuItem() With { _ Key .Text = "Count Lines...", _ Key .Image = Properties.Resources.CountLines _ } ' When we click, we'll count the lines. itemCountLines.Click += Function(sender, args) CountLines() ' Add the item to the context menu. menu.Items.Add(itemCountLines) ' Return the menu. Return menu End Function ''' <summary> ''' Counts the lines in the selected files. ''' </summary> Private Sub CountLines() ' Builder for the output. Dim builder = New StringBuilder() ' Go through each file. For Each filePath As var In SelectedItemPaths ' Count the lines. builder.AppendLine(String.Format("{0} - {1} Lines", Path.GetFileName(filePath), File.ReadAllLines(filePath).Length)) Next ' Show the ouput. MessageBox.Show(builder.ToString()) End Sub End Class '======================================================= 'Service provided by Telerik (www.telerik.com) 'Conversion powered by NRefactory. 'Twitter: @telerik 'Facebook: facebook.com/telerik '=======================================================
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5