TextSelection Property

Returns the selected portion of the page that is displayed in the viewer control as text. Read/write IMiSelectableItem.

expression.TextSelection

*expression   * Required. An expression that returns an MiDocView object.

Remarks

You can retrieve the user's selection in the viewer control as text (using the TextSelection property, which returns an IMiSelectableItem object) or as an image (using the ImageSelection property, which returns an IMiSelectableImage object). You can access the recognized text and the individual words of a text selection, and you can export an image selection as an IPictureDisp object for display in another control. Both text and image selections also support the CopyToClipboard method and a method that returns the coordinates of the selection.

The SelectionChanged event fires when the user makes a selection or changes the selection in the viewer control.

The TextSelection and ImageSelection properties raise a run-time error if nothing is selected in the viewer control.

Example

The following example reports the page number and the coordinates of each bounding rectangle in the user's text selection in the viewer control.

Sub TestTextSelection()

  Dim miTextSel As MODI.IMiSelectableItem
  Dim miSelectRects As MODI.miSelectRects
  Dim miSelectRect As MODI.miSelectRect
  Dim strTextSelInfo As String
  
  Set miTextSel = MiDocView1.TextSelection
  Set miSelectRects = miTextSel.GetSelectRects
  strTextSelInfo = _
    "Bounding rectangle page & coordinates: " & vbCrLf
  For Each miSelectRect In miSelectRects
    With miSelectRect
      strTextSelInfo = strTextSelInfo & _
        .PageNumber & ", " & .Top & ", " & _
        .Left & ", " & .Bottom & ", " & _
        .Right & vbCrLf
    End With
  Next
  MsgBox strTextSelInfo, vbInformation + vbOKOnly, _
    "Text Selection Info"
    
  Set miSelectRect = Nothing
  Set miSelectRects = Nothing
  Set miTextSel = Nothing
  
End Sub

Applies to | MiDocView Object