AfterViewerLassoDrawn event
This event is fired when the user draws a rectangle on the viewer. It enables you to insert extra functionality based on the selection made with the lasso tool.
ValidationForm_AfterViewerLassoDrawn( _
ByVal pXDoc As CASCADELib.CscXDocument, _
ByVal PageIndex As Long, _
ByVal pField As CASCADELib.CscXDocField, _
ByVal TopPos As Long, _
ByVal LeftPos As Long, _
ByVal Width As Long, _
ByVal Height As Long, _
ByRef bCancel As Boolean _
)
- pXDoc
-
XDocument object that is currently loaded.
- PageIndex
-
Zero-based index of the currently selected page.
- pField
-
Field object that is currently active.
- TopPos
-
Top position of the frame on the displayed image in the viewer.
- LeftPos
-
Left position of the frame on the displayed image in the viewer.
- Width
-
Width of the frame on the displayed image in the viewer.
- Height
-
Height of the frame on the displayed image in the viewer.
- bCancel
-
Setting this flag to TRUE the results of the selected region are not written into currently selected field.
For example, in partnership with the ButtonClicked event, you can let the user decide whether to insert a selection from the image into the MiniViewer using the lasso without affecting the field value of the corresponding field, or overwrite the field contents and insert the selected text into both the field and MiniViewer.
Overriding the default lasso behavior
'This works in partnership with the ButtonClicked event. The state of the button determines whether the field value is inserted or not.
Private Sub ValidationForm_AfterViewerLassoDrawn(ByVal pXDoc As CASCADELib.CscXDocument, ByVal PageIndex As Long, ByVal pField As CASCADELib.CscXDocField, ByVal TopPos As Long, ByVal LeftPos As Long, ByVal Width As Long, ByVal Height As Long, ByRef bCancel As Boolean)
Dim img As CscImage
'Get displayed image
img = pXDoc.CDoc.Pages.ItemByIndex(PageIndex).GetImage
Dim sSavedImage As String
Select Case pField.Name
Case "Crop"
If m_crop Then
'Call the function that saves the selected lasso area and return the file name
Dim bSaved As Boolean
sSavedImage = CropImage(img, LeftPos, TopPos, Width, Height, bSaved)
'If the cropped area is sucessfully saved update the field
If bSaved = True Then
'Set the correct field coordinates so that the MiniViewer shows the same snippet as the saved one:
pField.Width = Width
pField.Top = TopPos
pField.Left = LeftPos
pField.Height = Height
pField.PageIndex = PageIndex
'Set the field value to the filename containing the snippet and set it to valid
pField.Text = sSavedImage
pField.Valid = True
bCancel = True
End If
m_crop = False
End If
End Select
End Sub
Private Function CropImage(ByVal img As CscImage, ByVal LeftPos As Integer, ByVal TopPos As Integer, ByVal Width As Integer, ByVal Height As Integer, ByRef bSaved) As String
On Error GoTo Err
Dim snippet As New CscImage
snippet.CreateImage(CscImgColFormatBinary, Width, Height, img.XResolution, img.YResolution)
snippet.CopyRect(img, LeftPos, TopPos, 0, 0, Width, Height)
Dim sFilename As String
sFilename = "C:\Snippet\snippet.tif"
snippet.Save(sFilename, CscImgFileFormatTIFFFaxG4)
bSaved = True
CropImage = sFilename
Exit Function
Err:
bSaved = False
End Function
This event is not available for folder fields or the folder field validation pane.