Link Search Menu Expand Document

Take Screenshots During Recording - VB.NET

Screen Capturing SDK sample in VB.NET demonstrating ‘Take Screenshots During Recording’

Form1.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
		Me.buttonScreenshot = New System.Windows.Forms.Button()
		Me.buttonStop = New System.Windows.Forms.Button()
		Me.buttonStart = New System.Windows.Forms.Button()
		Me.SuspendLayout()
		'
		'buttonScreenshot
		'
		Me.buttonScreenshot.Enabled = False
		Me.buttonScreenshot.Location = New System.Drawing.Point(108, 41)
		Me.buttonScreenshot.Name = "buttonScreenshot"
		Me.buttonScreenshot.Size = New System.Drawing.Size(100, 23)
		Me.buttonScreenshot.TabIndex = 5
		Me.buttonScreenshot.Text = "Take Screenshot"
		Me.buttonScreenshot.UseVisualStyleBackColor = True
		'
		'buttonStop
		'
		Me.buttonStop.Enabled = False
		Me.buttonStop.Location = New System.Drawing.Point(27, 58)
		Me.buttonStop.Name = "buttonStop"
		Me.buttonStop.Size = New System.Drawing.Size(75, 23)
		Me.buttonStop.TabIndex = 4
		Me.buttonStop.Text = "Stop"
		Me.buttonStop.UseVisualStyleBackColor = True
		'
		'buttonStart
		'
		Me.buttonStart.Location = New System.Drawing.Point(27, 29)
		Me.buttonStart.Name = "buttonStart"
		Me.buttonStart.Size = New System.Drawing.Size(75, 23)
		Me.buttonStart.TabIndex = 3
		Me.buttonStart.Text = "Start"
		Me.buttonStart.UseVisualStyleBackColor = True
		'
		'Form1
		'
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(234, 111)
		Me.Controls.Add(Me.buttonScreenshot)
		Me.Controls.Add(Me.buttonStop)
		Me.Controls.Add(Me.buttonStart)
		Me.Name = "Form1"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		Me.Text = "Form1"
		Me.ResumeLayout(False)

	End Sub
	Private WithEvents buttonScreenshot As System.Windows.Forms.Button
	Private WithEvents buttonStop As System.Windows.Forms.Button
	Private WithEvents buttonStart As System.Windows.Forms.Button

End Class

Form1.vb
Imports BytescoutScreenCapturingLib

Public Class Form1

	' NOTE: if you are getting error like "invalid image" related to loading the SDK's dll then 
	' try to do the following:
	' 1) remove the reference to the SDK by View - Solution Explorer
	' then click on References, select Bytescout... reference name and right-click it and select Remove
	' 2) To re-add click on the menu: Project - Add Reference
	' 3) In "Add Reference" dialog switch to "COM" tab and find "BytescoutScreenCapturing 1.0 Type Library"
	' 4) Select it and click "Add" 
	' 5) Recompile the application 
	' Note: if you need to run on both x64 and x86 then please make sure you have set "Embed Interop Types" to True for this reference

	Dim _capturer As Capturer = Nothing

	Dim _screencastCount As Integer = 0
	Dim _screenshotCount As Integer = 0

	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

		' Create and setup Capturer object:

		_capturer = New Capturer()

		' Capture the full screen
		_capturer.CapturingType = CaptureAreaType.catScreen

		' Set movie width and height to the current monitor dimensions
		_capturer.OutputWidth = _capturer.MonitorWidth
		_capturer.OutputHeight = _capturer.MonitorHeight

		' Setup screenshots
		_capturer.ScreenshotImageFormat = ScreenshotImageType.ssitPng ' Save images in PNG format
		_capturer.ScreenshotOutputFolder = "\."	' Save to the current folder
		_capturer.ScreenshotSavingType = ScreenshotSavingType.ssstManual ' Take screenshots manually

	End Sub

	Private Sub buttonStart_Click(sender As Object, e As EventArgs) Handles buttonStart.Click

		_screencastCount = _screencastCount + 1
		Dim fileName As String = String.Format("screencast{0}.wmv", _screencastCount)

		' Start screen recording
		_capturer.OutputFileName = fileName
		_capturer.Run()

		buttonStart.Enabled = False
		buttonStop.Enabled = True
		buttonScreenshot.Enabled = True

	End Sub

	Private Sub buttonStop_Click(sender As Object, e As EventArgs) Handles buttonStop.Click

		' Stop recording
		_capturer.Stop()

		buttonStart.Enabled = True
		buttonStop.Enabled = False
		buttonScreenshot.Enabled = False

		MessageBox.Show("Screencast saved to " + _capturer.OutputFileName, ProductName)

	End Sub

	Private Sub buttonScreenshot_Click(sender As Object, e As EventArgs) Handles buttonScreenshot.Click

		_screenshotCount = _screenshotCount + 1
		Dim fileName As String = String.Format("screenshot{0}.png", _screenshotCount)

		' Take screenshot during the recording
		_capturer.TakeScreenshot(fileName)

		MessageBox.Show("Screenshot saved to " + fileName, ProductName)

	End Sub

End Class

Resources.Designer.vb
'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by a tool.
'     Runtime Version:4.0.30319.42000
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict On
Option Explicit On


Namespace My.Resources
    
    'This class was auto-generated by the StronglyTypedResourceBuilder
    'class via a tool like ResGen or Visual Studio.
    'To add or remove a member, edit your .ResX file then rerun ResGen
    'with the /str option, or rebuild your VS project.
    '''<summary>
    '''  A strongly-typed resource class, for looking up localized strings, etc.
    '''</summary>
    <Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
     Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
     Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
     Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
    Friend Module Resources

        Private resourceMan As Global.System.Resources.ResourceManager

        Private resourceCulture As Global.System.Globalization.CultureInfo

        '''<summary>
        '''  Returns the cached ResourceManager instance used by this class.
        '''</summary>
        <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
        Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
            Get
                If Object.ReferenceEquals(resourceMan, Nothing) Then
                    Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("TakeScreenshotsDuringRecording.Resources", GetType(Resources).Assembly)
                    resourceMan = temp
                End If
                Return resourceMan
            End Get
        End Property

        '''<summary>
        '''  Overrides the current thread's CurrentUICulture property for all
        '''  resource lookups using this strongly typed resource class.
        '''</summary>
        <Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
        Friend Property Culture() As Global.System.Globalization.CultureInfo
            Get
                Return resourceCulture
            End Get
            Set(ByVal value As Global.System.Globalization.CultureInfo)
                resourceCulture = value
            End Set
        End Property
    End Module
End Namespace

Settings.Designer.vb
'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by a tool.
'     Runtime Version:4.0.30319.42000
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict On
Option Explicit On


Namespace My

    <Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
     Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0"), _
     Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
    Partial Friend NotInheritable Class MySettings
        Inherits Global.System.Configuration.ApplicationSettingsBase

        Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings)

#Region "My.Settings Auto-Save Functionality"
#If _MyType = "WindowsForms" Then
        Private Shared addedHandler As Boolean

        Private Shared addedHandlerLockObject As New Object

        <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
        Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
            If My.Application.SaveMySettingsOnExit Then
                My.Settings.Save()
            End If
        End Sub
#End If
#End Region

        Public Shared ReadOnly Property [Default]() As MySettings
            Get

#If _MyType = "WindowsForms" Then
                   If Not addedHandler Then
                        SyncLock addedHandlerLockObject
                            If Not addedHandler Then
                                AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
                                addedHandler = True
                            End If
                        End SyncLock
                    End If
#End If
                Return defaultInstance
            End Get
        End Property
    End Class
End Namespace

Namespace My
    
    <Global.Microsoft.VisualBasic.HideModuleNameAttribute(),  _
     Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _
     Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()>  _
    Friend Module MySettingsProperty
        
        <Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")>  _
        Friend ReadOnly Property Settings() As Global.TakeScreenshotsDuringRecording.My.MySettings
            Get
                Return Global.TakeScreenshotsDuringRecording.My.MySettings.Default
            End Get
        End Property
    End Module
End Namespace

Download Source Code (.zip)

Return to the previous page Explore Screen Capturing SDK