ByteScout PDF Suite - VB.NET - Set PDF viewer Selection Options and use CustomPaint event with PDF Viewer SDK - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout PDF Suite – VB.NET – Set PDF viewer Selection Options and use CustomPaint event with PDF Viewer SDK

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Suite – VB.NET – Set PDF viewer Selection Options and use CustomPaint event with PDF Viewer SDK

How to set PDF viewer selection options and use custompaint event with PDF viewer SDK in VB.NET and ByteScout PDF Suite

Step-by-step tutorial on how to set PDF viewer selection options and use custompaint event with PDF viewer SDK in VB.NET

Quickly learn how to set PDF viewer selection options and use custompaint event with PDF viewer SDK in VB.NET with this sample source code. ByteScout PDF Suite can set PDF viewer selection options and use custompaint event with PDF viewer SDK. It can be applied from VB.NET. ByteScout PDF Suite is the set that includes 6 SDK products to work with PDF from generating rich PDF reports to extracting data from PDF documents and converting them to HTML. This bundle includes PDF (Generator) SDK, PDF Renderer SDK, PDF Extractor SDK, PDF to HTML SDK, PDF Viewer SDK and PDF Generator SDK for Javascript.

This prolific sample source code in VB.NET for ByteScout PDF Suite contains various functions and other necessary options you should do calling the API to set PDF viewer selection options and use custompaint event with PDF viewer SDK. Follow the instructions from scratch to work and copy the VB.NET code. If you want to use these VB.NET sample examples in one or many applications then they can be used easily.

ByteScout PDF Suite free trial version is available on our website. VB.NET and other programming languages are supported.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

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

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

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 r As Rectangle = Rectangle.Round(pdfViewerControl1.Selection(i)) r = pdfViewerControl1.TranslateRectangleToViewport(r) Dim textSize As Size = TextRenderer.MeasureText(_labels(i), Font) Dim textRectangle As New Rectangle(r.Left, r.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

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

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

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next