问题
In Visual Studio 2010, the only option you can create is a commandbar under "Tools" on the "MenuBar". In some cases, I would want to know how to place the command bar on the standard bar, or be found when I right-click a project file.
Example:
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar =
((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.
CommandBars)["MenuBar"];
By default it shows "MenuBar" and I am certain there is others, such as "Standard". However I am unable to find the resources or documentation for the list, and I wonder if anyone know where to look for list of these "Names".
Thank you guys in advance.
回答1:
I needed to figure this out while working on a visual studio plug-in. It looks like it depends on what you have installed. For example, I have some clear case CommandBars available to me because I work with the clear case integration plug-in. I'll echo that the more common ones are "Code Window", "Project", "MenuBar", "Solution", and "Item". To specifically answer your question, you would use the "Standard" and "Project" command bars.
To generate a list of all CommandBars you can create a visual studio plug-in and paste the following code into OnStartupComplete in Connect.cs:
CommandBars commandBars = (CommandBars)_applicationObject.CommandBars;
StringBuilder sb = new StringBuilder();
foreach (CommandBar cbar in commandBars)
{
sb.AppendLine(cbar.Name);
}
Clipboard.SetText(sb.ToString());
Results (over 300):
MenuBar
Standard
Build
Context Menus
Data Design
Formatting
Style Application
HTML Source Editing
Class Designer Toolbar
Text Editor
Workflow
Dialog Editor
Image Editor
Style Sheet
Source Control
Recorder
Microsoft XML Editor
Query Designer
View Designer
Database Diagram
Table Designer
Layout
Help
Debug Location
Debug
Report Formatting
Report Borders
Device
Microsoft Office Excel 2007
Microsoft Office Excel 2003
Microsoft Office Word 2007
Microsoft Office Word 2003
Test Tools
CrystalReportMain
CrystalReportInsert
ClearCase - Base
ClearCase - UCM
Error List
Docked Window
Menu Designer
Properties Window
Toolbox
Task List
Results List
Stub Project
No Commands Available
Command Window
AutoHidden Windows
Expansion Manager
Find Regular Expression Builder
Replace Regular Expression Builder
Wild Card Expression Builder
Wild Card Expression Builder
External Tools Arguments
External Tools Directories
Easy MDI Tool Window
Easy MDI Document Window
Easy MDI Dragging
Open Drop Down
Object Browser Objects Pane
Object Browser Members Pane
Object Browser Description Pane
Find Symbol
Drag and Drop
Bookmark Window
Error Correction
EzMDI Files
Ca&ll Browser
Preview Changes
Discover Service References
Smart Tag
Editor Context Menus
Class View Context Menus
Debugger Context Menus
Project and Solution Context Menus
Other Context Menus
Sort By
Show Columns
Implement Interface
Resolve
Refactor
Organize Usings
Create Private Accessor
Class View Multi-select Project references Items
Class View Multi-select Project references members
Class View Project
Class View Item
Class View Folder
Class View Grouping Folder
Class View Multi-select
Class View Multi-select members
Class View Member
Class View Grouping Members
Class View Project References Folder
Class View Project Reference
Class View Project Reference Item
Class View Project Reference Member
Project
Solution Folder
Cross Project Solution Project
Cross Project Solution Item
Cross Project Project Item
Cross Project Multi Project
Cross Project Multi Item
Cross Project Multi Solution Folder
Cross Project Multi Project/Folder
Item
Folder
Reference Root
Reference Item
Web Reference Folder
App Designer Folder
Web Project Folder
Web Folder
Web Item
Web SubWeb
References
Misc Files Project
Solution
Code Window
XAML Editor
Surface
DataSourceContext
DbTableContext
DataTableContext
RelationContext
FunctionContext
ColumnContext
QueryContext
DataAccessorContext
Context
Basic Context
Context
Context
Context
HTML Context
Script Context
ASPX Context
ASAX Context
ASPX Code Context
ASAX Code Context
ASPX VB Code Context
ASAX VB Code Context
ASMX Code Context
ASMX VB Code Context
Change &View
Static Node
Object Node
Multiple Static Nodes
Multiple Homogenous Object Nodes
Multiple Heterogenous Object Nodes
Multiple Heterogenous Nodes
Add &New
Selection
Container
TraySelection
Document Outline
Component Tray
Propertysheet
Configuration
Project
Multi-Select
System Propertysheet
Topic Menu
Topic Source Menu
Favorites Window Context Menu
Data Sources
Server Explorer
Managed Resources Editor Context Menu
Settings Designer
My Extensibility
Class Designer Context Menu
Class Diagram Context Menu
Class Details Context Menu
Selection
&Zoom
Page Layout
Designer Actions
&Navigation Tools
Resource View
Resource Editors
Resource Dialog Editors
Binary Editor
CSSDocOutline
CSSSource
Checkin Dialog Context Menu
Pending Checkin Window Context Menu
Standard TreeGrid context menu
GetVersion Dialog Context Menu
Check Out Dialog Context Menu
Macro
Module
Project
Root
TocContext
ResListContext
Query Diagram Pane
Query Diagram Table
Query Diagram Table Column
Query Diagram Join Line
Query Diagram Multi-select
Query Grid Pane
Query SQL Pane
Query Results Pane
Database Designer
Database Designer Table
Database Designer Relationship
Text Annotation
Database Project
DB Project Connection
DB Project Folder
Database References Folder
Folders
DB Project File
Query
Script
Database Reference Node
Files
Multi-select
PropertyBrowser
Editor
Script Outline
DefaultContext
ImageContext
SelectionContext
AnchorContext
Step Into Specific
Autos Window
Breakpoint
Load Symbols From
Breakpoints Window
Call Stack Window
Thread Tip Window
Data Tip Window
Disassembly Window
Locals Window
Memory Window
Modules Window
Output Window
Processes Window
Registers Window
Threads Window
Watch Window
Script Project
Thread IP Marker
Thread IP Markers
Control
Report
Row/Column
Cell
Field Chooser
Row/Column
Chart
Registry
File System
File System
File Types
User Interface
Launch Conditions
Custom Actions
New
Add
Add Special Folder
View
Project Node
A&dd
Cab Project Node
A&dd
File nodes
Dep. file nodes
Assembly nodes
Dep. assembly nodes
MSM nodes
Dep. MSM nodes
Output nodes
Simple file nodes
Simple output nodes
Dependency node
Multiple selections
Dep. Multiple selections
View
Editor
ORDesigner Context Menu
ORDesigner Context Menu
ORDesigner Context Menu
OTBObjCtxtMenu
SIDE Left Pane Context Menu
SIDE CertMgr Context Menu
Registry
File System
File System
New
Add
Add Special Folder
View
Project Node
A&dd
Cab Project Node
A&dd
File nodes
Dep. file nodes
Assembly nodes
Dep. assembly nodes
MSM nodes
Dep. MSM nodes
Output nodes
Dependency node
Multiple selections
Dep. Multiple selections
View
AppNet Designer Context
AppNet Project Node Context
Exe Project
Debug
Test Results Context Menu
Test List Editor Context Menu
Test List Context Menu
Test Run Context Menu
View Context Menu
Group
Database
Edit Text
Formula Parameter
Section
Default
Object Selection
Insert to Report
SchemaExplorer
AddNewItem
MicrosoftDataEntityDesign Context
MicrosoftDataEntityDesign Context
Find Checkouts
Pending Solution Checkins
Views Folder item context menu
UCM Project item context menu
View item context menu
Solution item context menu
Deliver
Rebase
ClearCase search Context Menus
System
回答2:
I only know of a few, and I am too wondering this, since I would like to know the name of the html code window in asp.net.
but here are the ones I know: "Code Window" (right-click code menu) "Tools" "MenuBar" "Standard"
EDIT: Also you can put a for loop to look through the commandbar names. (enumeration)
回答3:
I think you can get all commandbars by enumerate : CommandBars.GetEnumerator
回答4:
To find the name of a special command bar, this helps me very well. Just implement into the OnConnection():
CommandBars cmdBars = (CommandBars)applicationObject.CommandBars;
if (createCommand != null)
{
for (int i = 0; i <= cmdBars.Count; i++)
{
try
{
Type curType = cmdBars[i].GetType();
CommandBar commBarProject = cmdBars[i];
if (commBarProject != null)
{
creatorButton = (CommandBarButton)createCommand.AddControl(
commBarProject, commBarProject.Controls.Count + 1);
creatorButton.Caption = "ViewModel - " + cmdBars[i].Name;
}
}
catch (Exception){}
}
}
With every right click you will get the name.
来源:https://stackoverflow.com/questions/2946211/visual-studio-commandbar-names