TRY889 2019-11-04 03:43 采纳率: 33.3%
浏览 432
已采纳

VB.NET 判断PPT是否播放状态

在C#下 原帖

测试通过
将C#转成VB.NET提示 找不到公共成员SlideShowBegin
请大神指点下是怎么回事!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

namespace PPTEventTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private PowerPoint.Application oPPT;

    private void button1_Click(object sender, EventArgs e)
    {
        oPPT = new PowerPoint.Application();
        oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
        oPPT.Activate();

        oPPT.SlideShowBegin += new PowerPoint.EApplication_SlideShowBeginEventHandler(SlideShowBegin);
        oPPT.SlideShowEnd += new PowerPoint.EApplication_SlideShowEndEventHandler(SlideShowEnd);

    }

    private void SlideShowEnd(PowerPoint.Presentation Pres)
    {
        this.listBox1.Items.Add("结束放映");
    }

    private void SlideShowBegin(PowerPoint.SlideShowWindow Wn)
    {
        this.listBox1.Items.Add("开始放映");
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
    }

    private void button2_Click(object sender, EventArgs e)
    {

        oPPT.SlideShowBegin -= SlideShowBegin;
        oPPT.SlideShowEnd -= SlideShowEnd;
        oPPT.ActivePresentation.Saved = Microsoft.Office.Core.MsoTriState.msoTrue;
        oPPT.ActivePresentation.Close();

        oPPT.Quit();
        oPPT = null;
        //GC.Collect();
    }

}

}

转成VB.NET

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports PowerPoint = Microsoft.Office.Interop.PowerPoint

Namespace PPTEventTest
Public Partial Class Form1
Inherits Form

    Public Sub New()
        InitializeComponent()
    End Sub

    Private oPPT As PowerPoint.Application

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        oPPT = New PowerPoint.Application()
        oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
        oPPT.Activate()
        oPPT.SlideShowBegin += New PowerPoint.EApplication_SlideShowBeginEventHandler(AddressOf SlideShowBegin)
        oPPT.SlideShowEnd += New PowerPoint.EApplication_SlideShowEndEventHandler(AddressOf SlideShowEnd)
    End Sub

    Private Sub SlideShowEnd(ByVal Pres As PowerPoint.Presentation)
        Me.listBox1.Items.Add("结束放映")
    End Sub

    Private Sub SlideShowBegin(ByVal Wn As PowerPoint.SlideShowWindow)
        Me.listBox1.Items.Add("开始放映")
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
    End Sub

    Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
        oPPT.SlideShowBegin -= AddressOf SlideShowBegin
        oPPT.SlideShowEnd -= AddressOf SlideShowEnd
        oPPT.ActivePresentation.Saved = Microsoft.Office.Core.MsoTriState.msoTrue
        oPPT.ActivePresentation.Close()
        oPPT.Quit()
        oPPT = Nothing
    End Sub
End Class

End Namespace

  • 写回答

1条回答

  • threenewbee 2019-11-04 10:06
    关注

    oPPT.SlideShowBegin += New PowerPoint.EApplication_SlideShowBeginEventHandler(AddressOf SlideShowBegin)

    VB.NET不用+=
    用AddHandler oPPT.SlideShowBegin AddressOf SlideShowBegin

    https://blog.csdn.net/qincode/article/details/12945547

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料