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

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

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题