Bu makalede, Microsoft Visual Basic .NET 2003 kullanılarak geliştirilen bir Otomasyon istemciden gelen Microsoft Office PowerPoint olayları işlemek açıklamaktadır.
Bir olay işleyicisi oluşturmak
Visual Basic. NET'i kullanarak bir olay işleyicisi oluşturmak için aşağıdaki yöntemlerden birini kullanabilirsiniz. Seçtiğiniz yöntem, nasıl olay işleyicisi, bir olay ile ilişkilendirmek istediğiniz, bağlıdır.
Yöntem 1
Genellikle, bir olay işleyicisi WithEvents sözcüğüyle Handles anahtar sözcüğünü kullanarak oluşturun. WithEvents anahtar sözcüğünü kullanarak bir nesne başvurusu değişkenini bildirdiğinizde, Visual Basic .NET nesnesinin olaylara çalışma zamanında otomatik olarak bağlanır. Bir nesnenin belirli bir olay tanıtıcı, ilgili işleyiciye'sınıfı ' ni kullanarak eklemek için liste ve kod içinde iken Visual Studio .NET ortamında yöntemi listesini görüntüleyin.
Yöntem 2
Visual Basic .NET, olayları işlemek için başka bir yol sağlar. Böylece, dinamik olarak başlatın ve dinamik olarak belirli bir olay için olay işlemeyi durdur AddHandler deyimi ve RemoveHandler ekstresi kullanabilirsiniz.
Not Olay işleyicilerini oluşturmak için WithEvents anahtar sözcüğünü kullanırsanız, System.Reflection.TargetInvocationException bir özel durum bildirimi alabilir. Bu nedenle, AddHandler olay olay işleyicilerini oluşturmak için kullanın.
PowerPoint olayları işleyen bir Visual Basic .NET otomasyon istemci oluşturma
Aşağıdaki adımlar kümeleri AddHandler deyimi PowerPoint Visual Basic .NET kullanılarak geliştirilen bir Otomasyon istemciden uygulama olayları işlemek için nasıl kullanılacağını gösterir.
Bir Visual Basic .NET projesini oluşturmak için aşağıdaki adımları izleyin:
Başlangıç Microsoft Visual Studio .NET 2003.
Dosya menüsünden Yeni ' yi tıklatın ve sonra Project ' i tıklatın.
Project Types listesinde Visual Basic Projeleri) tıklatın. Şablonlar listesinde Windows uygulama ' yı tıklatın.
PowerPointEvents adını ve sonra Tamam ' ı tıklatın.
Varsayılan olarak, Form1 adlı bir form oluşturulur.
Microsoft PowerPoint Nesne Kitaplığı'na ve Microsoft Graph Nesnesi Kitaplığı'na başvuruları eklemek için <a0></a0>, aşağıdaki adımları izleyin:
Proje) menüsünde Add Reference ' ı tıklatın.
COM sekmesinde, aşağıdakilerden birini tıklatın ve sonra da <a2>Seç</a2>'i tıklatın:
Microsoft Office PowerPoint 2007 için Microsoft PowerPoint 12.0 Nesne Kitaplığı ' ı tıklatın.
Microsoft Office PowerPoint 2003 için Microsoft PowerPoint 11.0 Nesne Kitaplığı ' ı tıklatın.
COM sekmesinde, aşağıdakilerden birini tıklatın ve sonra da <a2>Seç</a2>'i tıklatın:
Microsoft Graph 12.0 için Microsoft Graph 12.0 Nesne Kitaplığı ' ı tıklatın.
Microsoft Graph 11.0 için Microsoft Graph 11.0 Nesne Kitaplığı ' ı tıklatın.
Başvuru Ekle iletişim kutusuna seçimlerinizi kabul etmek için Tamam ' ı tıklatın.
Formu çift tıklatın.
Kod penceresi açılır.
Form1.vb dosyasının en üstünde aşağıdaki kodu ekleyin:
Görünüm) menüsünde, araç kutusu ' nu tıklatın ve sonra da Form1'e bir düğme ekleyin.
Button1</a1> çift tıklatın.
Kod penceresi, altında <a2>Button1_Click</a2> olay açar.
Kod penceresinde Button1_Click</a0> olayından önce aşağıdaki kodu koy:
Dim oApp As PowerPoint.Application
Dim oPres As PowerPoint.Presentation
Için <a2>Button1_Click</a2> olay aşağıdaki kodu ekleyin:
Const sTemplate = "C:\Program Files\Microsoft Office\Templates\Presentation Designs\Orbit.pot"
' If the previous template is not available, change the template name to a template name that is on your system.
Const sVideo = "C:\WINDOWS\system32\oobe\images\intro.wmv"
Dim oPresentations As PowerPoint.Presentations
Dim oSlides As PowerPoint.Slides
Dim oSlide As PowerPoint.Slide
Dim oShapes As PowerPoint.Shapes
Dim oShape As PowerPoint.Shape
Dim oMovie As PowerPoint.Shape
Dim oAnimationSettings As PowerPoint.AnimationSettings
Dim oPlaySettings As PowerPoint.PlaySettings
Dim oTextFrame As PowerPoint.TextFrame
Dim oTextRange As PowerPoint.TextRange
Dim oFont As PowerPoint.Font
Dim oOLEFormat As PowerPoint.OLEFormat
Dim oShadow As PowerPoint.ShadowFormat
Dim oForeColor As PowerPoint.ColorFormat
Dim oRange As PowerPoint.SlideRange
Dim oSlideShowTransition As PowerPoint.SlideShowTransition
'Start PowerPoint and then make the PowerPoint window visible but minimized.
oApp = New PowerPoint.Application
'Add event handlers.
AddHandler oApp.SlideShowBegin, AddressOf oApp_SlideShowBegin
AddHandler oApp.SlideShowNextSlide, AddressOf oApp_SlideShowNextSlide
AddHandler oApp.PresentationClose, AddressOf oApp_PresentationClose
oApp.Visible = True
oApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
'Create a new presentation that is based on the specified template.
oPresentations = oApp.Presentations
oPres = oPresentations.Open(sTemplate, , , True)
'Build slide 1.
'Add text to the slide, change the font, and then insert or position a
'movie on the first slide.
oSlides = oPres.Slides
oSlide = oSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
oShapes = oSlide.Shapes
oShape = oShapes.Item(1)
oTextFrame = oShape.TextFrame
oTextRange = oTextFrame.TextRange
oTextRange.Text = "My sample presentation"
oFont = oTextRange.Font
oFont.Name = "Comic Sans MS"
oFont.Size = 48
oMovie = oShapes.AddMediaObject(sVideo, 150, 150, 500, 350)
oAnimationSettings = oMovie.AnimationSettings
oPlaySettings = oAnimationSettings.PlaySettings
oPlaySettings.PlayOnEntry = True
oPlaySettings.HideWhileNotPlaying = True
'NAR to release references.
NAR(oPlaySettings)
NAR(oAnimationSettings)
NAR(oMovie)
NAR(oFont)
NAR(oTextRange)
NAR(oTextFrame)
NAR(oShape)
NAR(oShapes)
NAR(oSlide)
NAR(oSlides)
'Build slide 2.
'Add text to the slide title and then format the text. Also, add a chart to the
'slide and then change the chart type to a 3D Column Clustered.
oSlides = oPres.Slides
oSlide = oSlides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
oShapes = oSlide.Shapes
oShape = oShapes.Item(1)
oTextFrame = oShape.TextFrame
oTextRange = oTextFrame.TextRange
oTextRange.Text = "My chart"
oFont = oTextRange.Font
oFont.Name = "Comic Sans MS"
oFont.Size = 48
Dim oChart As Graph.Chart
oShape = oShapes.AddOLEObject(150, 150, 480, 320, "MSGraph.Chart.8")
oOLEFormat = oShape.OLEFormat
oChart = oOLEFormat.Object
oChart.ChartType = Graph.XlChartType.xl3DColumnClustered
'NAR to release references.
NAR(oChart)
NAR(oOLEFormat)
NAR(oFont)
NAR(oTextRange)
NAR(oTextFrame)
NAR(oShape)
NAR(oShapes)
NAR(oSlide)
NAR(oSlides)
'Build slide 3.
'Add a text effect to the slide and then apply shadows to the text effect.
oSlides = oPres.Slides
oSlide = oSlides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank)
oSlide.FollowMasterBackground = False
oShapes = oSlide.Shapes
oShape = oShapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect27, _
"The End", "Impact", 96, False, False, 230, 200)
oShadow = oShape.Shadow
oForeColor = oShadow.ForeColor
oForeColor.SchemeColor = PowerPoint.PpColorSchemeIndex.ppForeground
oShadow.Visible = True
oShadow.OffsetX = 3
oShadow.OffsetY = 3
'NAR to release references.
NAR(oShadow)
NAR(oForeColor)
NAR(oShape)
NAR(oShapes)
NAR(oSlide)
NAR(oSlides)
'Modify the slide show transition settings for all three slides in
'the presentation.
Dim SlideIdx(3) As Integer
SlideIdx(0) = 1
SlideIdx(1) = 2
SlideIdx(2) = 3
oSlides = oPres.Slides
oRange = oSlides.Range(SlideIdx)
oSlideShowTransition = oRange.SlideShowTransition
oSlideShowTransition.AdvanceOnTime = False
oSlideShowTransition.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut
'Run the slide show in a separate method.
RunSlideShow()
'NAR to release references.
NAR(oSlideShowTransition)
NAR(oRange)
NAR(oSlides)
'Close the presentation without saving changes and then quit PowerPoint.
oPres.Saved = True
oPres.Close()
'NAR the presentation objects.
NAR(oPres)
NAR(oPresentations)
'Remove all event handlers.
RemoveHandler oApp.SlideShowBegin, AddressOf oApp_SlideShowBegin
RemoveHandler oApp.SlideShowNextSlide, AddressOf oApp_SlideShowNextSlide
RemoveHandler oApp.PresentationClose, AddressOf oApp_PresentationClose
'Quit PowerPoint.
oApp.Quit()
NAR(oApp)
GC.Collect()
Kod penceresinde a?a??daki Button1_Click</a1> olay kodu koy:
Private Sub RunSlideShow()
Dim oSettings As PowerPoint.SlideShowSettings
Dim oSlideShowWindows As PowerPoint.SlideShowWindows
oSettings = oPres.SlideShowSettings
oSettings.StartingSlide = 1
oSettings.EndingSlide = 3
'Run the slide show. Wait for the slide show to finish.
oSettings.Run()
oSlideShowWindows = oApp.SlideShowWindows
On Error Resume Next
Do While oSlideShowWindows.Count >= 1
System.Windows.Forms.Application.DoEvents()
Loop
NAR(oSlideShowWindows)
NAR(oSettings)
End Sub
'NAR function to remove reference.
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
Aşağıdaki olay işleyicilerini önceki kod altına ekleyin:
'Event Handlers
Private Sub oApp_SlideShowBegin(ByVal Wn As Microsoft.Office.Interop.PowerPoint.SlideShowWindow)
'Change the position and the size of the slide show window.
Dim oView As PowerPoint.SlideShowView
With Wn
.Height = 325
.Width = 400
.Left = 100
.Activate()
End With
'Start the movie at the first slide.
oView = Wn.View
oView.Next()
NAR(oView)
NAR(Wn)
End Sub
Private Sub oApp_SlideShowNextSlide(ByVal Wn As Microsoft.Office.Interop.PowerPoint.SlideShowWindow)
'Change the color and the type of pointer depending on the slide.
Dim Showpos As Integer
Dim oView As PowerPoint.SlideShowView
Dim oColorFormat As PowerPoint.ColorFormat
oView = Wn.View
Showpos = oView.CurrentShowPosition + 1
If Showpos = 3 Then
oColorFormat = oView.PointerColor
oColorFormat.RGB = RGB(255, 0, 0)
oView.PointerType = PowerPoint.PpSlideShowPointerType.ppSlideShowPointerPen
Else
oColorFormat = oView.PointerColor
oColorFormat.RGB = RGB(0, 0, 0)
oView.PointerType = PowerPoint.PpSlideShowPointerType.ppSlideShowPointerArrow
End If
NAR(oColorFormat)
NAR(oView)
NAR(Wn)
End Sub
Private Sub oApp_PresentationClose(ByVal Pres As Microsoft.Office.Interop.PowerPoint.Presentation)
'Before you close the presentation, save the presentation as HTML.
Pres.SaveAs("C:\TestEvents.htm", PowerPoint.PpSaveAsFileType.ppSaveAsHTML)
NAR(Pres)
End Sub
Deneyin
Uygulamayı çalıştırmak için F5 tuşuna basın.
Button1</a1> düğmesini tıklatın.
PowerPoint Slayt gösterisini başlatır. Aşağıdaki dikkat edin:
Otomasyon oluşturmak ve Visual Basic .NET 2002 veya Visual Basic .NET 2003 kullanarak, sunuyu PowerPoint 2002'yi veya bir Office PowerPoint 2003 sunusu göstermek için nasıl kullanılır
ÖNEMLİ: Bu makale, bir kişi tarafından çevrilmek yerine, Microsoft makine-çevirisi yazılımı ile çevrilmiştir. Microsoft size hem kişiler tarafından çevrilmiş, hem de makine-çevrisi ile çevrilmiş makaleler sunar. Böylelikle, bilgi bankamızdaki tüm makalelere, kendi dilinizde ulaşmış olursunuz. Bununla birlikte, makine tarafından çevrilmiş makaleler mükemmel değildir. Bir yabancının sizin dilinizde konuşurken yapabileceği hatalar gibi, makale; kelime dağarcığı, söz dizim kuralları veya dil bilgisi açısından yanlışlar içerebilir. Microsoft, içeriğin yanlış çevrimi veya onun müşteri tarafından kullanımından doğan; kusur, hata veya zarardan sorumlu değildir. Microsoft ayrıca makine çevirisi yazılımını sıkça güncellemektedir.
Teşekkürler! Görüşleriniz, destek içeriğimizi geliştirmemize yardımcı olmak için kullanılmaktadır. Diğer yardım seçenekleri için, lütfen Yardım ve Destek Giriş Sayfasını ziyaret edin.