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 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度