[英]PPT VSTO: how to excute shortcut over office's internal command
我很幸運地找到了一個名為globalmousekeyhook的項目,通過它我可以設置我的 PPT VSTO 插件的快捷方式。
核心部分代碼如下。
當我按下定義的快捷方式時,我的插件的 function 和 PPT 的內部命令都會被執行。
這有一個副作用,即我的插件觸發的 window 不會被聚焦。
我嘗試添加frm.activate()
或frm.focus
,但它們都不起作用。
我該怎么做才能只執行我的插件的 function? 任何意見將不勝感激。
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Gma.System.MouseKeyHook;
namespace PowerPointAddIn1
{
public partial class ThisAddIn
{
public static PowerPoint.Application PPTApp;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
var QRun = Combination.FromString("Alt+E");
Action actionQRun = ShowQRunWin;
var assignment = new Dictionary<Combination, Action>
{
{QRun, actionQRun}
};
Hook.AppEvents().OnCombination(assignment);
}
public void ShowQRunWin()
{
CMDForm frm = new CMDForm();
frm.FormBorderStyle = FormBorderStyle.FixedSingle; //set it un-resizeable
frm.MaximizeBox = false; //remove maximize button
frm.MinimizeBox = false; //remove minimize button
frm.Show();
frm.Activate();
frm.Focus();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new RibbonUI();
}
}
}
您所指的項目允許通過設置KeyPressEventArgs.Handled屬性來取消任何進一步的操作,該屬性設置一個指示事件是否已處理的值 - true
繞過控件的默認處理; 否則, false
也將事件傳遞給默認控制處理程序。
另一種方法是重新利用相應的(如果有的話)功能區按鈕。 在這種情況下,也涵蓋了鍵盤快捷鍵。 在 Office Fluent Ribbon 上的臨時重新調整命令用途一文中閱讀有關此內容的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.