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

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 cplex运行后参数报错是为什么
  • ¥15 之前不小心删了pycharm的文件,后面重新安装之后软件打不开了
  • ¥15 vue3获取动态宽度,刷新后动态宽度值为0
  • ¥15 升腾威讯云桌面V2.0.0摄像头问题
  • ¥15 关于Python的会计设计
  • ¥15 聚类分析 设计k-均值算法分类器,对一组二维模式向量进行分类。
  • ¥15 stm32c8t6工程,使用hal库
  • ¥15 找能接spark如图片的,可议价
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 博通raid 的写入速度很高也很低