Select the product you need help with
HOWTO: Getting the "View" command bar of Visual Studio .NET from an add-inArticle ID: 555186 - View products that this article applies to. SUMMARYThis article describes how to get the "View" command bar of the main menu of Visual Studio .NET in order to add new entries to it from an add-in. SYMPTOMSThis article describes how to get the "View" command bar of the main menu of Visual Studio .NET in order to add new entries to it from an add-in, since DTE.CommandBars.Item("View") returns a different command bar. MORE INFORMATIONIn order to retrieve the "View" command bar of the main menu of Visual Studio .NET, you have to iterate through the controls of the "MenuBar" command bar, casting them to a command bar popup and checking its name. The following VB.NET add-in snippet shows the technique: Private m_objDTE As EnvDTE.DTE Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, _ ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection Dim objMenuBarCommandBar As CommandBar Dim objViewCommandBar As CommandBar Dim objCommandBarControl As CommandBarControl Dim objCommandBarPopup As CommandBarPopup Dim sControlList As String m_objDTE = DirectCast(application, EnvDTE.DTE) Try objMenuBarCommandBar = m_objDTE.CommandBars.Item("MenuBar") For Each objCommandBarControl In objMenuBarCommandBar.Controls If objCommandBarControl.Type = MsoControlType.msoControlPopup Then objCommandBarPopup = DirectCast(objCommandBarControl, CommandBarPopup) If objCommandBarPopup.CommandBar.Name = "View" Then objViewCommandBar = objCommandBarPopup.CommandBar Exit For End If End If Next sControlList = "Controls currently visible on the View CommandBar: " & Microsoft.VisualBasic.ControlChars.CrLf For Each objCommandBarControl In objViewCommandBar.Controls If objCommandBarControl.Visible Then sControlList &= Microsoft.VisualBasic.ControlChars.CrLf & objCommandBarControl.Caption End If Next System.Windows.Forms.MessageBox.Show(sControlList) Catch objException As System.Exception System.Windows.Forms.MessageBox.Show(objException.ToString) End Try End Sub PropertiesArticle ID: 555186 - Last Review: August 27, 2004 - Revision: 1.0 APPLIES TO
COMMUNITY SOLUTIONS CONTENT DISCLAIMER MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES. |



Back to the top








