/Source Code/ExperimentalPowerPoint/frmMain.vb
Visual Basic | 56 lines | 40 code | 12 blank | 4 comment | 0 complexity | 3d255f6cded922715793203c4377497f MD5 | raw file
- Imports Microsoft.Office.Interop.PowerPoint
-
- Public Class frmMain
-
- Public Sub New()
-
- InitializeComponent()
- txtFileName.Text = My.Computer.FileSystem.SpecialDirectories.Desktop
-
- End Sub
-
- Private Sub btnSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFile.Click
-
- dlgOpen.FileName = txtFileName.Text
- If dlgOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
- txtFileName.Text = dlgOpen.FileName
- End If
-
- End Sub
-
- Private Sub btnShowSlide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowSlide.Click
-
- ' Open PowerPoint
- Dim App As Application
- Dim Pres As Presentation
- App = New Application
- App.Visible = True
- App.WindowState = PpWindowState.ppWindowMinimized
-
- ' Open the presentation
- Pres = App.Presentations.Open(txtFileName.Text, , , True)
-
- ' Process each slide
- Dim SlideCount As Integer = Pres.Slides.Count
- Dim Graphics As Graphics = pbSlides.CreateGraphics
- For SlideIndex As Integer = 1 To Math.Min(1, SlideCount)
-
- ' Save the slide to disk as an image
- Dim FileName As String = My.Computer.FileSystem.SpecialDirectories.Desktop + "\" + SlideIndex.ToString + ".png"
- If IO.File.Exists(FileName) Then Throw New Exception("File '" + FileName + "' already exists.")
- Pres.Slides(SlideIndex).Export(FileName, "PNG", pbSlides.Width, pbSlides.Height)
-
- ' Display the slide image
- Dim Image As Image = Image.FromFile(FileName)
- Graphics.DrawImage(Image, 0, 0)
- Image.Dispose()
-
- ' Delete the file
- IO.File.Delete(FileName)
-
- Next
- Graphics.Dispose()
-
- End Sub
-
- End Class