PageRenderTime 25ms CodeModel.GetById 11ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/Source Code/ExperimentalPowerPoint/frmMain.vb

#
Visual Basic | 56 lines | 40 code | 12 blank | 4 comment | 0 complexity | 3d255f6cded922715793203c4377497f MD5 | raw file
 1Imports Microsoft.Office.Interop.PowerPoint
 2
 3Public Class frmMain
 4
 5    Public Sub New()
 6
 7        InitializeComponent()
 8        txtFileName.Text = My.Computer.FileSystem.SpecialDirectories.Desktop
 9
10    End Sub
11
12    Private Sub btnSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFile.Click
13
14        dlgOpen.FileName = txtFileName.Text
15        If dlgOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
16            txtFileName.Text = dlgOpen.FileName
17        End If
18
19    End Sub
20
21    Private Sub btnShowSlide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowSlide.Click
22
23        ' Open PowerPoint
24        Dim App As Application
25        Dim Pres As Presentation
26        App = New Application
27        App.Visible = True
28        App.WindowState = PpWindowState.ppWindowMinimized
29
30        ' Open the presentation
31        Pres = App.Presentations.Open(txtFileName.Text, , , True)
32
33        ' Process each slide
34        Dim SlideCount As Integer = Pres.Slides.Count
35        Dim Graphics As Graphics = pbSlides.CreateGraphics
36        For SlideIndex As Integer = 1 To Math.Min(1, SlideCount)
37
38            ' Save the slide to disk as an image
39            Dim FileName As String = My.Computer.FileSystem.SpecialDirectories.Desktop + "\" + SlideIndex.ToString + ".png"
40            If IO.File.Exists(FileName) Then Throw New Exception("File '" + FileName + "' already exists.")
41            Pres.Slides(SlideIndex).Export(FileName, "PNG", pbSlides.Width, pbSlides.Height)
42
43            ' Display the slide image
44            Dim Image As Image = Image.FromFile(FileName)
45            Graphics.DrawImage(Image, 0, 0)
46            Image.Dispose()
47
48            ' Delete the file
49            IO.File.Delete(FileName)
50
51        Next
52        Graphics.Dispose()
53
54    End Sub
55
56End Class