AxImageViewer read event

  • Last Post 23 February 2017
ibrahim posted this 21 February 2017


I'm using VisualComponents code sample for C#, I want to get selected string test while debugging, How could i intercept for this when "Read" button is pressed

Best regards

Order By: Standard | Newest | Votes
ibrahim posted this 23 February 2017

Any answer???????????

Oksana Serdyuk posted this 28 February 2017


Sorry for the delay!

You can use the OnCommand event of the ICommandEvents interface in order that it handles the event for any command of a Visual Component. These commands can appear in the context menu of a component and in its toolbar (if exists). The list of all available commands you can find in the Developer’s Help → Visual Components Reference → Enumerations → MenuItemEnum. Alos please read the Developer’s Help → Guided Tour → Advanced Techniques → Using Graphical User Interface Elements → Customizing the Context Menu and Toolbar of a Visual Component for more information.

The Image Viewer component can be connected to the ComponentSynchronizer component, in which case all the events in Image Viewer will be automatically transmitted to other components connected to the Synchronizer and the whole application will work synchronously. To know how the Synchronizer works in this or that situation, see the Developer’s Help → Guided Tour → Advanced Techniques → Using Graphical User Interface Elements → How Component Synchronizer Works.

Below you can find an example how you can implement your scenario, when after drawing a text block and pressing the "Read" button, you get the recognized text shown, for example, in the message box:

Synchronizer.ImageViewer.Commands.OnCommand += Commands_OnCommand;

// Handler for the OnCommand event of the Image Viewer
private void Commands_OnCommand(FineReaderVisualComponents.MenuItemEnum MenuItem, out bool Cancel)
    Cancel = false;
    FREngine.IntsCollection selectedBlocks = Synchronizer.ImageViewer.GetSelectedBlocksIndices();
    if (selectedBlocks.Count == 1 && MenuItem == FineReaderVisualComponents.MenuItemEnum.MI_Read)
        if (Synchronizer.ImageViewer.FRPage.Layout.Blocks[selectedBlocks[0]].Type == FREngine.BlockTypeEnum.BT_Text)
            Synchronizer.ImageViewer.Commands.DoCommand(FineReaderVisualComponents.MenuItemEnum.MI_ReadBlock, true);
            FREngine.TextBlock textBlock = Synchronizer.ImageViewer.FRPage.Layout.Blocks[selectedBlocks[0]].GetAsTextBlock();
            FREngine.Paragraphs paragraphs = textBlock.Text.Paragraphs;

            string recognizedText = paragraphs.Item(0).Text;

            int paragraphsCount = paragraphs.Count;

            for (int i = 1; i < paragraphsCount; i++)
                recognizedText = recognizedText + paragraphs.Item(i).Text;

            Cancel = true;
            Cancel = false;