Skip to main content
A newer version of this page is available. .

PdfViewer.Select(RectangleF) Method

Selects the document content located in the specified rectangle.

Namespace: DevExpress.XtraPdfViewer

Assembly: DevExpress.XtraPdfViewer.v19.1.dll

Declaration

public void Select(
    RectangleF clientRectangle
)

Parameters

Name Type Description
clientRectangle RectangleF

A RectangleF structure that is the target rectangle.

Remarks

The overloaded Select method uses the client coordinate system. Refer to the Coordinate Systems topic for more information.

The code sample below shows how to copy selected text to the Clipboard.

bool mouseButtonPressed = false;
PdfDocumentPosition startPosition;
PdfDocumentPosition endPosition;

void pdfViewer1_MouseDown(object sender, MouseEventArgs e)
{
  if (e.Button == MouseButtons.Left)
  {
      //Retrieve the initial mouse position
      startPosition = pdfViewer1.GetDocumentPosition(e.Location);
      endPosition = null;
      mouseButtonPressed = true;
      pdfViewer1.Invalidate();
  }
}

void pdfViewer1_MouseMove(object sender, MouseEventArgs e)
{
  if (mouseButtonPressed)
  {
      //Obtain the final position
      endPosition = pdfViewer1.GetDocumentPosition(e.Location);
      pdfViewer1.Invalidate();
  }
}


void pdfViewer1_MouseUp(object sender, MouseEventArgs e)
{
    mouseButtonPressed = false;
    if (startPosition == null || endPosition == null)
        return;
    var start = pdfViewer1.GetClientPoint(startPosition);
    var end = pdfViewer1.GetClientPoint(endPosition);
    RectangleF rect = new RectangleF(Math.Min(start.X, end.X),
        Math.Min(start.Y, end.Y),
        Math.Abs(start.X - end.X),
        Math.Abs(start.Y - end.Y));


    //Select the content located in the target rectangle
    pdfViewer1.Select(rect);
    PdfSelectionContent content = pdfViewer1.GetSelectionContent();
    if (content.ContentType == PdfSelectionContentType.Text)

    //Copy selection to Clipboard
        pdfViewer1.CopyToClipboard();
    MessageBox.Show("The selection is copied to Clipboard");
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Select(RectangleF) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also