Link Search Menu Expand Document

Set PDF Viewer Selection Options and Use CustomPaint Event - VB.NET

PDF Viewer SDK sample in VB.NET demonstrating ‘Set PDF Viewer Selection Options and Use CustomPaint Event’

Form1.Designer.vb
��Partial Class Form1

	''' <summary>

	''' Required designer variable.

	''' </summary>

	Private components As System.ComponentModel.IContainer = Nothing



	''' <summary>

	''' Clean up any resources being used.

	''' </summary>

	''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

	Protected Overrides Sub Dispose(disposing As Boolean)

		If disposing AndAlso (components IsNot Nothing) Then

			components.Dispose()

		End If

		MyBase.Dispose(disposing)

	End Sub



	#Region "Windows Form Designer generated code"



	''' <summary>

	''' Required method for Designer support - do not modify

	''' the contents of this method with the code editor.

	''' </summary>

	Private Sub InitializeComponent()

        Me.pdfViewerControl1 = New Bytescout.PDFViewer.PDFViewerControl()

        Me.toolStrip1 = New System.Windows.Forms.ToolStrip()

        Me.tsbOpen = New System.Windows.Forms.ToolStripButton()

        Me.cbLockSelection = New System.Windows.Forms.CheckBox()

        Me.cbAllowResizeSelection = New System.Windows.Forms.CheckBox()

        Me.cbMultiSelectMode = New System.Windows.Forms.CheckBox()

        Me.toolStrip1.SuspendLayout()

        Me.SuspendLayout()

        '

        'pdfViewerControl1

        '

        Me.pdfViewerControl1.AllowResizeSelectionRectangles = True

        Me.pdfViewerControl1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _

            Or System.Windows.Forms.AnchorStyles.Left) _

            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)

        Me.pdfViewerControl1.BackColor = System.Drawing.SystemColors.ButtonShadow

        Me.pdfViewerControl1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle

        Me.pdfViewerControl1.Location = New System.Drawing.Point(12, 97)

        Me.pdfViewerControl1.MouseMode = Bytescout.PDFViewer.MouseMode.Selection

        Me.pdfViewerControl1.MultiSelectMode = True

        Me.pdfViewerControl1.Name = "pdfViewerControl1"

        Me.pdfViewerControl1.RegistrationKey = Nothing

        Me.pdfViewerControl1.RegistrationName = Nothing

        Me.pdfViewerControl1.Size = New System.Drawing.Size(1153, 568)

        Me.pdfViewerControl1.TabIndex = 0

        '

        'toolStrip1

        '

        Me.toolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.tsbOpen})

        Me.toolStrip1.Location = New System.Drawing.Point(0, 0)

        Me.toolStrip1.Name = "toolStrip1"

        Me.toolStrip1.Size = New System.Drawing.Size(1177, 25)

        Me.toolStrip1.TabIndex = 1

        Me.toolStrip1.Text = "toolStrip1"

        '

        'tsbOpen

        '

        Me.tsbOpen.ImageTransparentColor = System.Drawing.Color.Magenta

        Me.tsbOpen.Name = "tsbOpen"

        Me.tsbOpen.Size = New System.Drawing.Size(80, 22)

        Me.tsbOpen.Text = "&Open PDF"

        '

        'cbLockSelection

        '

        Me.cbLockSelection.AutoSize = True

        Me.cbLockSelection.Location = New System.Drawing.Point(12, 74)

        Me.cbLockSelection.Name = "cbLockSelection"

        Me.cbLockSelection.Size = New System.Drawing.Size(95, 17)

        Me.cbLockSelection.TabIndex = 2

        Me.cbLockSelection.Text = "Lock selection"

        Me.cbLockSelection.UseVisualStyleBackColor = True

        '

        'cbAllowResizeSelection

        '

        Me.cbAllowResizeSelection.AutoSize = True

        Me.cbAllowResizeSelection.Checked = True

        Me.cbAllowResizeSelection.CheckState = System.Windows.Forms.CheckState.Checked

        Me.cbAllowResizeSelection.Location = New System.Drawing.Point(12, 51)

        Me.cbAllowResizeSelection.Name = "cbAllowResizeSelection"

        Me.cbAllowResizeSelection.Size = New System.Drawing.Size(178, 17)

        Me.cbAllowResizeSelection.TabIndex = 3

        Me.cbAllowResizeSelection.Text = "Allow resize selection rectangles"

        Me.cbAllowResizeSelection.UseVisualStyleBackColor = True

        '

        'cbMultiSelectMode

        '

        Me.cbMultiSelectMode.AutoSize = True

        Me.cbMultiSelectMode.Checked = True

        Me.cbMultiSelectMode.CheckState = System.Windows.Forms.CheckState.Checked

        Me.cbMultiSelectMode.Location = New System.Drawing.Point(12, 28)

        Me.cbMultiSelectMode.Name = "cbMultiSelectMode"

        Me.cbMultiSelectMode.Size = New System.Drawing.Size(108, 17)

        Me.cbMultiSelectMode.TabIndex = 4

        Me.cbMultiSelectMode.Text = "Multi-select mode"

        Me.cbMultiSelectMode.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(1177, 677)

        Me.Controls.Add(Me.cbMultiSelectMode)

        Me.Controls.Add(Me.cbAllowResizeSelection)

        Me.Controls.Add(Me.cbLockSelection)

        Me.Controls.Add(Me.pdfViewerControl1)

        Me.Controls.Add(Me.toolStrip1)

        Me.Name = "Form1"

        Me.Text = "Form1"

        Me.toolStrip1.ResumeLayout(False)

        Me.toolStrip1.PerformLayout()

        Me.ResumeLayout(False)

        Me.PerformLayout()



    End Sub



	#End Region



    Private WithEvents pdfViewerControl1 As Bytescout.PDFViewer.PDFViewerControl

    Private WithEvents toolStrip1 As System.Windows.Forms.ToolStrip

    Private WithEvents tsbOpen As System.Windows.Forms.ToolStripButton

    Private WithEvents cbLockSelection As System.Windows.Forms.CheckBox

    Private WithEvents cbAllowResizeSelection As System.Windows.Forms.CheckBox

    Private WithEvents cbMultiSelectMode As System.Windows.Forms.CheckBox

End Class




Form1.vb
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Imports Bytescout.PDFViewer

Public Partial Class Form1
	Inherits Form
	Public Sub New()
		InitializeComponent()
	End Sub

	Protected Overrides Sub OnLoad(e As EventArgs)
		pdfViewerControl1.InputFile = "sample.pdf"

		MyBase.OnLoad(e)
	End Sub

    Private Sub tsbOpen_Click(sender As Object, e As EventArgs) Handles tsbOpen.Click
        Using openFileDialog As New OpenFileDialog()
            openFileDialog.Title = "Open PDF Document"
            openFileDialog.Filter = "PDF Files (*.pdf)|*.pdf|All Files|*.*"

            If openFileDialog.ShowDialog() = DialogResult.OK Then
                Me.Text = openFileDialog.FileName

                Cursor = Cursors.WaitCursor

                Try
                    pdfViewerControl1.InputFile = openFileDialog.FileName
                Catch exception As Exception
                    MessageBox.Show(exception.Message)
                Finally
                    Cursor = Cursors.[Default]
                End Try
            End If
        End Using
    End Sub

    Private Sub cbMultiSelectMode_CheckedChanged(sender As Object, e As EventArgs) Handles cbMultiSelectMode.CheckedChanged
        pdfViewerControl1.MultiSelectMode = cbMultiSelectMode.Checked
    End Sub

    Private Sub cbAllowResizeSelection_CheckedChanged(sender As Object, e As EventArgs) Handles cbAllowResizeSelection.CheckedChanged
        pdfViewerControl1.AllowResizeSelectionRectangles = cbAllowResizeSelection.Checked
    End Sub

    Private Sub cbLockSelection_CheckedChanged(sender As Object, e As EventArgs) Handles cbLockSelection.CheckedChanged
        pdfViewerControl1.LockSelection = cbLockSelection.Checked
    End Sub

	Private _labels As List(Of [String]) = New List(Of String)()

    Private Sub pdfViewerControl1_SelectionChanged(ByVal sender As Object, ByVal selectionChange As SelectionChange, ByVal selectionIndex As Integer) Handles pdfViewerControl1.SelectionChanged
        If pdfViewerControl1.Selection.Length > _labels.Count Then
            For i As Integer = _labels.Count To pdfViewerControl1.Selection.Length - 1
                _labels.Add(New Random().[Next]().ToString())
            Next
        End If
    End Sub

    Private Sub pdfViewerControl1_CustomPaint(sender As Object, e As PaintEventArgs) Handles pdfViewerControl1.CustomPaint
        ' Paint labels
        For i As Integer = 0 To pdfViewerControl1.Selection.Length - 1
            Dim pdfRect As RectangleF = pdfViewerControl1.SelectionInPoints(i)
            Dim pixelRect As Rectangle = pdfViewerControl1.TranslateRectangleFromPointsToPixels(pdfRect)

            Dim textSize As Size = TextRenderer.MeasureText(_labels(i), Font)
            Dim textRectangle As New Rectangle(pixelRect.Left, pixelRect.Top - textSize.Height - 6, textSize.Width + 2, textSize.Height + 2)

            e.Graphics.FillRectangle(Brushes.DarkBlue, textRectangle)
            TextRenderer.DrawText(e.Graphics, _labels(i), Font, textRectangle, Color.White, TextFormatFlags.HorizontalCenter Or TextFormatFlags.VerticalCenter)
        Next
    End Sub
End Class

Program.vb
Imports System.Collections.Generic
Imports System.Windows.Forms

NotInheritable Class Program
	Private Sub New()
	End Sub
	''' <summary>
	''' The main entry point for the application.
	''' </summary>
	<STAThread> _
	Private Shared Sub Main()
		Application.EnableVisualStyles()
		Application.SetCompatibleTextRenderingDefault(False)
		Application.Run(New Form1())
	End Sub
End Class

Resources.Designer.vb
��'------------------------------------------------------------------------------

' <auto-generated>

'     This code was generated by a tool.

'     Runtime Version:4.0.30319.34014

'

'     Changes to this file may cause incorrect behavior and will be lost if

'     the code is regenerated.

' </auto-generated>

'------------------------------------------------------------------------------



Namespace Properties





	''' <summary>

	'''   A strongly-typed resource class, for looking up localized strings, etc.

	''' </summary>

	' 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.

	<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")> _

	<System.Diagnostics.DebuggerNonUserCodeAttribute> _

	<System.Runtime.CompilerServices.CompilerGeneratedAttribute> _

	Friend Class Resources



		Private Shared resourceMan As Global.System.Resources.ResourceManager



		Private Shared resourceCulture As Global.System.Globalization.CultureInfo



		<System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _

		Friend Sub New()

		End Sub



		''' <summary>

		'''   Returns the cached ResourceManager instance used by this class.

		''' </summary>

		<System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _

		Friend Shared ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager

			Get

				If Object.ReferenceEquals(resourceMan, Nothing) Then

					Dim temp As New Global.System.Resources.ResourceManager("Example.Properties.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>

		<System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _

		Friend Shared Property Culture() As Global.System.Globalization.CultureInfo

			Get

				Return resourceCulture

			End Get

			Set

				resourceCulture = value

			End Set

		End Property



		''' <summary>

		'''   Looks up a localized resource of type System.Drawing.Bitmap.

		''' </summary>

		Friend Shared ReadOnly Property folder_page() As System.Drawing.Bitmap

			Get

				Dim obj As Object = ResourceManager.GetObject("folder_page", resourceCulture)

				Return DirectCast(obj, System.Drawing.Bitmap)

			End Get

		End Property

	End Class

End Namespace


Settings.Designer.vb
��'------------------------------------------------------------------------------

' <auto-generated>

'     This code was generated by a tool.

'     Runtime Version:4.0.30319.34014

'

'     Changes to this file may cause incorrect behavior and will be lost if

'     the code is regenerated.

' </auto-generated>

'------------------------------------------------------------------------------



Namespace Properties





	<System.Runtime.CompilerServices.CompilerGeneratedAttribute> _

	<System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")> _

	Friend NotInheritable Partial Class Settings

		Inherits Global.System.Configuration.ApplicationSettingsBase



		Private Shared defaultInstance As Settings = DirectCast(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()), Settings)



		Public Shared ReadOnly Property [Default]() As Settings

			Get

				Return defaultInstance

			End Get

		End Property

	End Class

End Namespace


Download Source Code (.zip)

Return to the previous page Explore PDF Viewer SDK