PageRenderTime 129ms CodeModel.GetById 11ms 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
  1. Imports Microsoft.Office.Interop.PowerPoint
  2. Public Class frmMain
  3. Public Sub New()
  4. InitializeComponent()
  5. txtFileName.Text = My.Computer.FileSystem.SpecialDirectories.Desktop
  6. End Sub
  7. Private Sub btnSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFile.Click
  8. dlgOpen.FileName = txtFileName.Text
  9. If dlgOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
  10. txtFileName.Text = dlgOpen.FileName
  11. End If
  12. End Sub
  13. Private Sub btnShowSlide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowSlide.Click
  14. ' Open PowerPoint
  15. Dim App As Application
  16. Dim Pres As Presentation
  17. App = New Application
  18. App.Visible = True
  19. App.WindowState = PpWindowState.ppWindowMinimized
  20. ' Open the presentation
  21. Pres = App.Presentations.Open(txtFileName.Text, , , True)
  22. ' Process each slide
  23. Dim SlideCount As Integer = Pres.Slides.Count
  24. Dim Graphics As Graphics = pbSlides.CreateGraphics
  25. For SlideIndex As Integer = 1 To Math.Min(1, SlideCount)
  26. ' Save the slide to disk as an image
  27. Dim FileName As String = My.Computer.FileSystem.SpecialDirectories.Desktop + "\" + SlideIndex.ToString + ".png"
  28. If IO.File.Exists(FileName) Then Throw New Exception("File '" + FileName + "' already exists.")
  29. Pres.Slides(SlideIndex).Export(FileName, "PNG", pbSlides.Width, pbSlides.Height)
  30. ' Display the slide image
  31. Dim Image As Image = Image.FromFile(FileName)
  32. Graphics.DrawImage(Image, 0, 0)
  33. Image.Dispose()
  34. ' Delete the file
  35. IO.File.Delete(FileName)
  36. Next
  37. Graphics.Dispose()
  38. End Sub
  39. End Class