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

ByteScout PDF Viewer SDK – VB.NET – Set PDF Viewer Selection Options and Use CustomPaint Event

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Viewer SDK – VB.NET – Set PDF Viewer Selection Options and Use CustomPaint Event

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

The tutorial shows how to set PDF viewer selection options and use custompaint event in VB.NET

Source code documentation samples provide quick and easy way to add a required functionality into your application. ByteScout PDF Viewer SDK: the visual component that you can use to quickly create your own pdf viewer application or add pdf vieweing functionality into your existing app. into your WinForms application. Includes support for selection using mouse, returns coordinates, you may add custom painting on top of pdf displayed. It can set PDF viewer selection options and use custompaint event in VB.NET.

The SDK samples like this one below explain how to quickly make your application do set PDF viewer selection options and use custompaint event in VB.NET with the help of ByteScout PDF Viewer SDK. In your VB.NET project or application you may simply copy & paste the code and then run your app! This basic programming language sample code for VB.NET will do the whole work for you to set PDF viewer selection options and use custompaint event.

Download free trial version of ByteScout PDF Viewer SDK from our website with this and other source code samples for VB.NET.

Try ByteScout PDF Viewer SDK today: Get 60 Day Free Trial or sign up for Web API

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

Try ByteScout PDF Viewer SDK today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)

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

Try ByteScout PDF Viewer SDK today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)

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

Try ByteScout PDF Viewer SDK today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)

VIDEO

ON-PREMISE VERSION

Get 60 Day Free Trial or Visit ByteScout PDF Viewer SDK page

Explore ByteScout PDF Viewer SDK documentation

WEB API

Sign Up for free Web API key

Explore Web API Documentation

prev
next