Powerful all-in-one PDF library for .NET
VS 2005/2008/2010/2012/2013

Drag-And-Drop Support In PDFOne .NET Viewer Control

Allow users to drag and drop PDF files on the PDFViewer component.

PDFViewer is the viewer component in PDFOne .NET. It is a multi-page PDF viewer and supports advanced features such as zooming, rotation, mousewheel scrolling, and keyboard shortcuts.

You can use the PDFViewer in a .NET Win forms application to display PDF documents. This can be very useful in an application that generates PDF statements or invoices and the user requires a preview before the document is e-mailed to recipients.

Or, if you were developing a multi-format document viewing application, somewhat similar to our ONEView application, (which does more than just displaying documents), then you may want the ability to display PDF documents that are simply dragged and dropped on the form.

PDFViewer can be programmed to support for drag-and-drop operations. For this, you need to handle the inherited Control.DragDrop event of the viewer like this.

private void pdfViewer1_DragDrop(object sender, DragEventArgs e) {
  // Check for a valid file drop
  if (e.Data.GetDataPresent(DataFormats.FileDrop)) {
    // Get names of files that were dropped
    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
    if (files.Length > 0) {
      // Display the first file that is droppped.

To ensure that only a PDF document is loaded by the viewer, you can handle the inherited Control.DragEnter event as shown below.

private void pdfViewer1_DragEnter(object sender, DragEventArgs e) {
  // Do not allow file drop (initially)
  e.Effect = DragDropEffects.None;
  if (!e.Data.GetDataPresent(DataFormats.FileDrop)) {
  string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
  if (files.Length > 0) {
    // Allow file drop for PDF files
    if (files[0].EndsWith(".pdf", true, null)) {
      e.Effect = DragDropEffects.Copy;

For these events to fire, you need to set the PDFViewer.AllowDrop property to true. You can add these event handlers to the .NET PDF viewer project described in the last month's article How To Create A PDF Viewer in PDFOne .NET v2.x and they will work fine.


Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.


A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2019 Gnostice Information Technologies Private Limited. All rights reserved.