PdfViewer.Select(RectangleF) Method
Selects the document content located in the specified rectangle.
Namespace: DevExpress.XtraPdfViewer
Assembly: DevExpress.XtraPdfViewer.v24.2.dll
NuGet Package: DevExpress.Win.PdfViewer
Declaration
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.
If the passed RectangleF object contains a part of the image, the method selects the entire image.
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");
}
See Also