我开发了一个PowerPoint插件,可将当前打开的演示文稿转换为.wmv文件。
这一切都很好用。当演示文稿转换时,我可以在PowerPoint底部看到一个进度条以及一个红色的X,可以按下该X来取消转换过程。
有没有办法以编程方式调用此取消按钮?
这是我用来调用它并等待它完成的代码,但我也希望能够在它正在进行时取消它。
private void frmUpload_Load(object sender, EventArgs e)
{
try
{
progressBarUpload.Value = 0;
string exportName = "video_of_presentation";
string exportPath = @"C:\Windows\Temp\{0}.wmv";
// Export the currently open presentation
Microsoft.Office.Interop.PowerPoint.Application ppApplication = null;
ppApplication = new Microsoft.Office.Interop.PowerPoint.Application();
ppApplication.Activate();
ppApplication.ActivePresentation.SaveAs(String.Format(exportPath, exportName), Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsWMV);
lblUploadStatus.Text = "Status: Converting …";
new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
/* run your code here */
do
{
System.Threading.Thread.Sleep(500);
}
while (ppApplication.ActivePresentation.CreateVideoStatus != Microsoft.Office.Interop.PowerPoint.PpMediaTaskStatus.ppMediaTaskStatusDone);
backgroundWorker.RunWorkerAsync();
SetControlPropertyValue(lblUploadStatus, "text", "Status: Uploading …");
}).Start();
}
catch
{
lblUploadStatus.Text = "Status: Error Converting File.";
}
}
非常感谢任何帮助。
崔佛
答案 0 :(得分:0)