c# - 如何更改 Outlook VSTO 中的鼠标指针
问题描述
我正在尝试使用 Outlook 功能区中的自定义按钮将文件上传到远程服务器。发生以下步骤
- 用户单击功能区中的上传文件按钮,将看到文件选择器对话框。
- 将看到文件选择弹出窗口,用户选择一个或多个文件
- 单击确定按钮后,我只想更改默认光标以等待光标
- 文件上传完成后,我尝试恢复默认光标
我的代码如下
public void UploadFiles(Office.IRibbonControl control)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor
//some code which will call rest API to upload file
Cursor.Current = Cursors.default
}
}
但上面的代码并没有改变光标。该按钮出现在 Outlook 的撰写窗口中
解决方案
您需要导入 Word.DLL 然后使用以下代码
public void UploadFiles(Office.IRibbonControl control)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
Outlook.Inspector currentInspector = Globals.ThisAddIn.Application.ActiveInspector();
Word.Document document = currentInspector.WordEditor;
Word.Application wordApp = document.Application;
wordApp.System.Cursor = Word.WdCursorType.wdCursorWait;
//perform your task
//Switch to default Cursor
wordApp.System.Cursor = Word.WdCursorType.wdCursorNormal;
}
}
推荐阅读
- android - 使用改造安卓上传文件?
- postgresql - PGAdmin4 在 Mac 中每天都无法启动:错误“无法联系应用程序服务器”
- wordpress - 2Checkout 授权自 6 月以来失败
- google-app-engine - 如何使部署到谷歌云应用引擎的应用程序可用于某些白名单 IP
- java - 将类的实例添加到 Arraylist
- mysql - 用 Where 删除。程序会删除所有内容。为什么?
- java - 如何知道自定义 Java 节点是否包含在第二个节点中?
- android - 在 Android 上监听连接变化
- python - 如何在 Keras 中格式化 ImageDataGenerator 的 X 和 Y 数据?
- python - Can't install gcloud on Amazon Linux : invalid syntax