---
title: "Highlight a region in a PDF or an image in VB.NET"
canonical_url: "https://www.nutrient.io/guides/dotnet/samples/select-pdf-image-region-vbnet/"
md_url: "https://www.nutrient.io/guides/dotnet/samples/select-pdf-image-region-vbnet.md"
last_updated: "2026-05-14T21:57:26.876Z"
description: "Learn how to draw and modify highlighted regions in documents using VB.NET. Perfect for OMR and anchor applications. Enhance your document interactivity!"
---

# Highlight a region in PDF or an image in VB.NET

This example shows how to draw highlighted regions on top of a document. A highlighted region is a special feature that’s modifiable by mouse. It can be used to specify areas and highlight them, and it’s especially useful in anchor and OMR applications.

[Get Started](https://www.nutrient.io/sdk/dotnet/getting-started.md)

[All Samples](https://www.nutrient.io/guides/dotnet/samples.md)

[Download](https://www.nutrient.io/guides/dotnet/downloads.md)

[Launch Demo](https://www.nutrient.io/demo/)

---

### C#

[C#](https://www.nutrient.io/guides/dotnet/samples/select-pdf-image-region-cs.md)

### VB.NET

[VB.NET](https://www.nutrient.io/guides/dotnet/samples/select-pdf-image-region-vbnet.md)

```vb

'We assume that GdPicture has been correctly installed and unlocked.
'We assume the GdViewer object called GdViewer1 has been created and painted on the form.
Dim oGdPictureImaging As New GdPictureImaging
'Loading the image from a file.
Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("C:\\Image.tif")
'Checking if the image resource has been loaded correctly.
If oGdPictureImaging.GetStat() <> GdPictureStatus.OK
   MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Drawing regions Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
   'Displaying the image in the GdViewer.
   GdViewer1.DisplayFromGdPictureImage(imageId)
End If
oGdPictureImaging.Dispose()

'On the Mouse UP event on the GdViewer, create a highlighted region based on the rectangle of selection of the GdViewer.
'If no rectangle of selection is painted on the GdViewer, this event will do nothing.
Public Sub Draw_Region(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles GdViewer1.MouseUp
   'Initializing variables to hold the position of the rectangle of selection on the document.
   Dim leftArea As Integer, topArea As Integer, widthArea As Integer, heightArea As Integer
   'Checking if a rectangle of selection has been painted on the GdViewer.
   If GdViewer1.IsRect() Then
      'Getting the location of the selection on the document.
      GdViewer1.GetRectCoordinatesOnDocument(leftArea, topArea, widthArea, heightArea)
      'Setting the ROI on the document:
      'Adding a region in place of the rectangle of selection.
      Dim regionId As Integer = GdViewer1.AddRegion("Region", leftArea, topArea, widthArea, heightArea, GdPicture14.ForegroundMixMode.ForegroundMixModeMASKPEN, Color.Green)
      'Setting region border width.
      GdViewer1.SetRegionBorderWidth(regionId, 1)
      'Setting region border color.
      GdViewer1.SetRegionBorderColor(regionId, Color.Blue)
      'Redrawing the whole image.
      GdViewer1.ClearRect()
      GdViewer1.Redraw()
   End If
End Sub

```

This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.

---

## Related pages

- [Automatically rotate pages of a multipage TIFF file using OCR and VB.NET](/guides/dotnet/samples/auto-rotate-tiff-vbnet.md)
- [Automatically rotate pages of a multipage TIFF file using OCR and C#](/guides/dotnet/samples/auto-rotate-tiff-cs.md)
- [Convert PDFs, MS Office, and images to TIFF in C#](/guides/dotnet/samples/convert-to-tiff-cs.md)
- [Saving images into folders based on their barcode](/guides/dotnet/samples/barcode-auto-sorting-cs.md)
- [Saving images into folders based on their barcode](/guides/dotnet/samples/barcode-auto-sorting-vbnet.md)
- [Generate a multipage TIFF file using a compression mode per page in C#](/guides/dotnet/samples/create-multipage-tiff-cs.md)
- [Converting a Microsoft Word binary file document (DOC) to a Microsoft Word OpenXML document (DOCX) in C#](/guides/dotnet/samples/doc-to-docx-cs.md)
- [Merging two PDF documents by alternating pages from both files in VB.NET](/guides/dotnet/samples/merge-pdf-alternate-pages-vbnet.md)
- [Using an external OCR engine during PDF/OCR generation](/guides/dotnet/samples/integrate-omnipage-ocr-cs.md)
- [Converting a multipage PDF to a multipage TIFF using color detection in C#](/guides/dotnet/samples/pdf-to-tiff-color-detection-cs.md)
- [Merging two PDF documents by alternating pages from both files in C#](/guides/dotnet/samples/merge-pdf-alternate-pages-cs.md)
- [Converting a multipage PDF to a multipage TIFF using color detection in VB.NET](/guides/dotnet/samples/pdf-to-tiff-color-detection-vbnet.md)
- [Recompress existing PDFs using MRC compression in C#](/guides/dotnet/samples/recompress-pdf-mrc-cs.md)
- [Recompress an existing PDF using color detection in VB.NET](/guides/dotnet/samples/recompress-pdf-vbnet.md)
- [Recompress an existing PDF using color detection in C#](/guides/dotnet/samples/recompress-pdf-cs.md)
- [Recompress existing PDFs using MRC compression in VB.NET](/guides/dotnet/samples/recompress-pdf-mrc-vbnet.md)
- [Highlight and crop an image in C#](/guides/dotnet/samples/select-image-crop-area-cs.md)
- [Highlight and crop an image in VB.NET](/guides/dotnet/samples/select-image-crop-area-vbnet.md)
- [Choosing the appropriate OCR zone in C#](/guides/dotnet/samples/select-ocr-zone-cs.md)
- [Highlight a region in a PDF or an image in C#](/guides/dotnet/samples/select-pdf-image-region-cs.md)
- [Choosing the appropriate OCR zone in VB.NET](/guides/dotnet/samples/select-ocr-zone-vbnet.md)
- [Save bitonal TIFFs with VB.NET using photometric 0](/guides/dotnet/samples/tiff-photometric-vbnet.md)
- [Convert a multipage TIFF to a multipage JBIG2 in VB.NET](/guides/dotnet/samples/tiff-to-jbig2-vbnet.md)
- [Save bitonal TIFF images with C# and CCITT4](/guides/dotnet/samples/tiff-photometric-cs.md)
- [Convert a multipage TIFF to a multipage JBIG2 in C#](/guides/dotnet/samples/tiff-to-jbig2-cs.md)

