I want to programmatically select the word which mouse pointer is pointing to.
I tried drawing a Rectangle on the page but it didn't work (no rectangle).
Can you please help.
Code: Select all
private void ShowSymbolInfo(Point p)
{
if (imageViewer1.Image == null)
return;
lock (_document)
{
PdfPage page = FocusedPage;
if (page == null)
return;
PointF pt = imageViewer1.PointToImage(p);
Resolution resolution = imageViewer1.RenderingSettings.Resolution;
if (resolution.IsEmpty())
resolution = page.DefaultResolution;
page.PointToUnit(ref pt, resolution);
try
{
var region = page.TextRegion.GetWordSubregion(pt);
if (region != null)
{
using (var gr = PdfGraphics.FromPage(page))
{
var brush = new PdfBrush(Color.Gray, GraphicsStateBlendMode.Multiply);
gr.FillRectangle(brush, region.Rectangle);
}
statusLabel.Text = string.Format("Text: '{0}'",
region.TextContent);
}
else
{
if (statusLabel.Text.Length > 8 && statusLabel.Text.Substring(0, 6) == "Symbol")
statusLabel.Text = "";
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}