本文整理汇总了C#中System.Windows.Forms.Command.AddControl方法的典型用法代码示例。如果您正苦于以下问题:C# Command.AddControl方法的具体用法?C# Command.AddControl怎么用?C# Command.AddControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Command
的用法示例。
在下文中一共展示了Command.AddControl方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addTemporaryButtonTo
private void addTemporaryButtonTo(Command command, CommandBarPopup popup, string caption)
{
CommandBarButton button = (CommandBarButton)command.AddControl(popup.CommandBar, popup.Controls.Count + 1);
button.Caption = caption;
button.Style = MsoButtonStyle.msoButtonCaption;
button.BeginGroup = false;
button.Visible = true;
_buttons.Add(button);
}
示例2: setupCommandBars
private void setupCommandBars()
{
_iceConfigurationCmd = null;
try
{
_iceConfigurationCmd =
_applicationObject.Commands.Item(_addInInstance.ProgID + ".IceConfiguration", -1);
}
catch(ArgumentException)
{
object[] contextGUIDS = new object[] { };
_iceConfigurationCmd =
((Commands2)_applicationObject.Commands).AddNamedCommand2(_addInInstance,
"IceConfiguration",
"Ice Configuration...",
"Ice Configuration...",
true, -1, ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported +
(int)vsCommandStatus.vsCommandStatusEnabled,
(int)vsCommandStyle.vsCommandStylePictAndText,
vsCommandControlType.vsCommandControlTypeButton);
}
if(_iceConfigurationCmd == null)
{
MessageBox.Show("Error initializing Ice Visual Studio Add-in.\n" +
"Cannot create required commands",
"Ice Visual Studio Add-in",
MessageBoxButtons.OK,
MessageBoxIcon.Error,
MessageBoxDefaultButton.Button1,
(MessageBoxOptions)0);
return;
}
CommandBar toolsCmdBar = ((CommandBars)_applicationObject.CommandBars)["Tools"];
_iceConfigurationCmd.AddControl(toolsCmdBar, toolsCmdBar.Controls.Count + 1);
CommandBar projectCmdBar = projectCommandBar();
_iceConfigurationCmd.AddControl(projectCmdBar, projectCmdBar.Controls.Count + 1);
}
示例3: AddCommand
public void AddCommand()
{
try
{
if (string.IsNullOrEmpty(this.MenuName))
{
// No menu required
return;
}
Command cmdTmp;
CommandBars cmdBars = (CommandBars)appObj.CommandBars;
// Check any old versions of the command are not still hanging around
try
{
cmdTmp = appObj.Commands.Item(this.CommandName, UNKNOWN_CMD_ID);
cmdTmp.Delete();
}
catch { }
// this is an empty array for passing into the AddNamedCommand method
object[] contextUIGUIDs = null;
cmdTmp = appObj.Commands.AddNamedCommand(
this.addIn,
this.GetType().Name,
this.ButtonText,
this.ToolTip,
true,
this.Bitmap,
ref contextUIGUIDs,
(int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled);
foreach (string sMenuName in this.MenuName.Split(','))
{
CommandBar pluginCmdBar = null;
if (_cachedCommandBars.ContainsKey(sMenuName))
{
pluginCmdBar = _cachedCommandBars[sMenuName];
}
else
{
#if DENALI
//in VS2010, performance of cmdBars[sMenuName] is terrible: http://www.mztools.com/articles/2011/MZ2011005.aspx
//plus looking up cmdBars["Other Windows"] failsof the ones we're looking for are there
//performs better when you look at the root level of the CommandBars since most
foreach (CommandBar bar in cmdBars)
{
if (bar.Name == sMenuName)
{
pluginCmdBar = bar;
break;
}
}
//if not yet found, then recurse
if (pluginCmdBar == null)
{
foreach (CommandBar bar in cmdBars)
{
pluginCmdBar = RecurseCommandBarToFindCommandBarByName(bar, sMenuName);
if (pluginCmdBar != null) break;
}
}
#else
pluginCmdBar = cmdBars[sMenuName];
#endif
}
if (pluginCmdBar == null)
{
System.Windows.Forms.MessageBox.Show("Cannot get the " + this.MenuName + " menubar");
}
else
{
if (!_cachedCommandBars.ContainsKey(sMenuName))
{
_cachedCommandBars.Add(sMenuName, pluginCmdBar);
}
pluginCmd = cmdTmp;
CommandBarButton btn;
if (sMenuName == "Tools")
{
if (toolsCommandBarPopup == null)
{
toolsCommandBarPopup = (CommandBarPopup)pluginCmdBar.Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, 1, true);
toolsCommandBarPopup.CommandBar.Name = "BIDSHelperToolsCommandBarPopup";
toolsCommandBarPopup.Caption = "BIDS Helper";
}
btn = pluginCmd.AddControl(toolsCommandBarPopup.CommandBar, 1) as CommandBarButton;
SetCustomIcon(btn);
btn.BeginGroup = BeginMenuGroup;
toolsCommandBarPopup.Visible = true;
}
else if (AddCommandToMultipleMenus)
{
//.........这里部分代码省略.........
示例4: AddCommandToCmdBar
/// <summary>
/// Adds an command button to Visual Studio for the give command.
/// </summary>
/// <param name="command"></param>
/// <param name="cmdBar"></param>
/// <param name="buttonStyle"></param>
/// <returns></returns>
private CommandBarButton AddCommandToCmdBar(Command command, CommandBar cmdBar, MsoButtonStyle buttonStyle)
{
CommandBarButton tempCmdBarButton;
tempCmdBarButton = (CommandBarButton)command.AddControl(cmdBar, cmdBar.Controls.Count + 1);
tempCmdBarButton.BeginGroup = true;
tempCmdBarButton.Style = buttonStyle;
return tempCmdBarButton;
}
示例5: setupMenu
private void setupMenu()
{
object[] contextGuids = new object[] { };
Commands2 commands = (Commands2)applicationObject.Commands;
string toolsMenuName;
try
{
string resourceName;
ResourceManager resourceManager = new ResourceManager("PaZu.CommandBar", Assembly.GetExecutingAssembly());
CultureInfo cultureInfo = new CultureInfo(applicationObject.LocaleID);
if (cultureInfo.TwoLetterISOLanguageName == "zh")
{
CultureInfo parentCultureInfo = cultureInfo.Parent;
resourceName = String.Concat(parentCultureInfo.Name, "Tools");
}
else
{
resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
}
toolsMenuName = resourceManager.GetString(resourceName);
}
catch
{
toolsMenuName = "Tools";
}
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar =
((CommandBars)applicationObject.CommandBars)["MenuBar"];
CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
try
{
// todo: need to add custom icon instead of the icon 487 from VS
// and also change vsCommandStyle.vsCommandStyleText to
// vsCommandStyle.vsCommandStylePictAndText
jiraCommand = commands.AddNamedCommand2(
addInInstance, "PaZuShowHide", "Toggle Atlassian Connector Window", "Shows or hides Atlassian Connector window", true, 487,
ref contextGuids, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
(int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);
if ((jiraCommand != null) && (toolsPopup != null))
{
jiraCommand.AddControl(toolsPopup.CommandBar, 1);
}
}
catch (ArgumentException e)
{
Debug.WriteLine(e.Message);
}
}
示例6: OnConnection
/// <summary>
/// Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.
/// </summary>
/// <param name="application">
/// Root object of the host application.
/// </param>
/// <param name="connectMode">
/// Describes how the Add-in is being loaded.
/// </param>
/// <param name="addInInst">
/// Object representing this Add-in.
/// </param>
/// <param name="custom">
/// Array of custom params
/// </param>
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
applicationObjectField = (DTE2)application;
addInInstanceField = (AddIn)addInInst;
// Only execute the startup code if the connection mode is a startup mode
if (connectMode == ext_ConnectMode.ext_cm_Startup)
{
var contextGUIDS = new object[] { };
try
{
// Create a Command with name SolnExplContextMenuCS and then add it to the "Item" menubar for the SolutionExplorer
commandField = applicationObjectField.Commands.AddNamedCommand(addInInstanceField,
"Xsd2CodeAddin",
"Run Xsd2Code generation",
"Xsd2Code", true, 372,
ref contextGUIDS,
(int)
vsCommandStatus.
vsCommandStatusSupported
+
(int)
vsCommandStatus.
vsCommandStatusEnabled);
projectCmdBarField = ((CommandBars)applicationObjectField.CommandBars)["Item"];
if (projectCmdBarField == null)
{
MessageBox.Show("Cannot get the Project menubar", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
commandField.AddControl(projectCmdBarField, 1);
}
catch (Exception)
{
}
}
}
示例7: AddControlToToolsMenu
private void AddControlToToolsMenu(Command command, CommandBarPopup toolsPopup)
{
if (command != null && toolsPopup != null)
command.AddControl(toolsPopup.CommandBar, 1);
}
示例8: ShowRightClickShortcutInCodeWindow
private void ShowRightClickShortcutInCodeWindow(Command commandToShow)
{
Microsoft.VisualStudio.CommandBars.CommandBar commandBar = ((CommandBars)this._applicationObject.CommandBars)["Code Window"];
CommandBarControl commandBarControl = null;
foreach (CommandBarControl commandBarControl2 in commandBar.Controls)
{
if (commandBarControl2.Caption == "Add to CodeKeep")
{
commandBarControl = commandBarControl2;
break;
}
}
if (commandBarControl != null)
{
commandBarControl.Visible = true;
return;
}
commandToShow.AddControl(commandBar, 1);
}
示例9: OnConnection
/// <summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary>
/// <param term='application'>宿主应用程序的根对象。</param>
/// <param term='connectMode'>描述外接程序的加载方式。</param>
/// <param term='addInInst'>表示此外接程序的对象。</param>
/// <seealso class='IDTExtensibility2' />
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
if ((connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == Extensibility.ext_ConnectMode.ext_cm_Startup)&&!_initialized)
{
_usefulFunctions = new UsefulFunctions(_applicationObject, _addInInstance);
string keyGlobal = "Global::";
outliner.setApplicationObject(_applicationObject);
docEvents = _applicationObject.Events.get_DocumentEvents(null);
docEvents.DocumentOpened += new _dispDocumentEvents_DocumentOpenedEventHandler(docEvents_DocumentOpened);
eventTextEditor = _applicationObject.Events.get_TextEditorEvents(null);
eventTextEditor.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(eventTextEditor_LineChanged);
EnvDTE80.Events2 events = (EnvDTE80.Events2)_applicationObject.Events;
eventTextEditor2 = events.get_TextDocumentKeyPressEvents(null);
eventTextEditor2.BeforeKeyPress += new _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler(eventTextEditor2_BeforeKeyPress);
object[] contextGUIDS = new object[] { };
Commands2 commands = (Commands2)_applicationObject.Commands;
string toolsMenuName;
try
{
//若要将此命令移动到另一个菜单,则将“工具”一词更改为此菜单的英文版。
// 此代码将获取区域性,将其追加到菜单名中,然后将此命令添加到该菜单中。
// 您会在此文件中看到全部顶级菜单的列表
// CommandBar.resx.
string resourceName;
ResourceManager resourceManager = new ResourceManager("JrtCoder.CommandBar", Assembly.GetExecutingAssembly());
CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID);
if (cultureInfo.TwoLetterISOLanguageName == "zh")
{
System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
resourceName = String.Concat(parentCultureInfo.Name, "Tools");
keyGlobal = "全局::";
}
else
{
resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
}
toolsMenuName = resourceManager.GetString(resourceName);
}
catch
{
//我们试图查找“工具”一词的本地化版本,但未能找到。
// 默认值为 en-US 单词,该值可能适用于当前区域性。
toolsMenuName = "Tools";
}
//将此命令置于“工具”菜单上。
//查找 MenuBar 命令栏,该命令栏是容纳所有主菜单项的顶级命令栏:
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];
//在 MenuBar 命令栏上查找“工具”命令栏:
CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
//如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块,
// 只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。
try
{
try
{
formatAllCmd = _applicationObject.Commands.Item(GetFullCmd(FormatAll), -1);
formatSelectedCmd = _applicationObject.Commands.Item(GetFullCmd(FormatSelected), -1);
formatSettingsCmd = _applicationObject.Commands.Item(GetFullCmd(FormatSettings), -1);
AddRegionCmd = _applicationObject.Commands.Item(GetFullCmd(AddRegion), -1);
}
catch (System.Exception e)
{
}
try
{
if (formatAllCmd == null)
{
formatAllCmd = commands.AddNamedCommand2(_addInInstance, FormatAll, "格式化Js", "格式化全部javascript代码", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
}
if (formatSelectedCmd == null)
{
formatSelectedCmd = commands.AddNamedCommand2(_addInInstance, FormatSelected, "格式化选定的Js", "格式化选定的javascript代码", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
try
{
CommandBar cb = _usefulFunctions.GetCommandBar("HTML Context", null);
formatSelectedCmd.AddControl(cb, cb.accChildCount + 1);
cb = _usefulFunctions.GetCommandBar("Script Context", null);
formatSelectedCmd.AddControl(cb, cb.accChildCount + 1);
cb = _usefulFunctions.GetCommandBar("ASPX Context", null);
formatSelectedCmd.AddControl(cb, cb.accChildCount + 1);
}
//.........这里部分代码省略.........