如何解决PPT VSTO:如何在office内部命令上执行快捷方式
我很幸运地找到了一个名为 globalmousekeyhook 的项目,通过它我可以设置我的 PPT VSTO 插件的快捷方式。
核心部分代码如下。
当我按下定义的快捷键时,我的插件的功能和 PPT 的内部命令都会被执行。
这有一个副作用,即我的插件触发的窗口不会被聚焦。
我尝试添加 frm.activate()
或 frm.focus
,但它们都不起作用。
我该怎么做才能只执行我的插件的功能?任何评论都将得到认可。
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
也将事件传递给默认控件处理程序。
另一种方法是重新调整相应(如果有)功能区按钮的用途。在这种情况下,键盘快捷键也包括在内。在 Temporarily Repurpose Commands on the Office Fluent Ribbon 文章中阅读更多相关信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。