GdPicture.NET Reference Guide
AddRegion(String,Double,Double,Double,Double,Color,RegionFillMode) Method
Example 





GdPicture14.WPF Namespace > GdViewer Class : AddRegion(String,Double,Double,Double,Double,Color,RegionFillMode) Method
The name of the newly added highlighted region. It can be an empty string.
The horizontal (X) coordinate of the top left point, in inches, of the highlighted region's rectangle, related to the current page.
The vertical (Y) coordinate of the top left point, in inches, of the highlighted region's rectangle, related to the current page.
The width, in inches, of the highlighted region's rectangle, related to the current page.
The height, in inches, of the highlighted region's rectangle, related to the current page.
A color object that defines the fill color of the newly added highlighted region.
A member of the RegionFillMode enumeration. Specifies the fill mode used to combine the region fill color and the displayed area of the image covered by this region when highlighting.
Adds and highlights a new region on the current page of the document displayed in the GdViewer control according to what you have specified. This method uses inches to define the position and the size of the region's rectangle.

The region is highlighted immediately using the specified color. At the same, it is added to the list of all highlighted regions related to the displayed document. You can find out the number of currently defined highlighted regions using the RegionCount method.

Please note that highlighted regions are also determined using both SearchText(String,Int32,Boolean) and SearchText(String,Int32,Boolean,Boolean) methods.

You can also benefit from using both events related to highlighted regions, the RegionEdited event and the RegionSelected event, respectively the PreviewRegionEdited event and the PreviewRegionSelected event.

Syntax
'Declaration
 
Public Function AddRegion( _
   ByVal Name As String, _
   ByVal Left As Double, _
   ByVal Top As Double, _
   ByVal Width As Double, _
   ByVal Height As Double, _
   ByVal RegionColor As Color, _
   ByVal FillMode As GdViewer.RegionFillMode _
) As Integer
public int AddRegion( 
   string Name,
   double Left,
   double Top,
   double Width,
   double Height,
   Color RegionColor,
   GdViewer.RegionFillMode FillMode
)
public function AddRegion( 
    Name: String;
    Left: Double;
    Top: Double;
    Width: Double;
    Height: Double;
    RegionColor: Color;
    FillMode: GdViewer.RegionFillMode
): Integer; 
public function AddRegion( 
   Name : String,
   Left : double,
   Top : double,
   Width : double,
   Height : double,
   RegionColor : Color,
   FillMode : GdViewer.RegionFillMode
) : int;
public: int AddRegion( 
   string* Name,
   double Left,
   double Top,
   double Width,
   double Height,
   Color RegionColor,
   GdViewer.RegionFillMode FillMode
) 
public:
int AddRegion( 
   String^ Name,
   double Left,
   double Top,
   double Width,
   double Height,
   Color RegionColor,
   GdViewer.RegionFillMode FillMode
) 

Parameters

Name
The name of the newly added highlighted region. It can be an empty string.
Left
The horizontal (X) coordinate of the top left point, in inches, of the highlighted region's rectangle, related to the current page.
Top
The vertical (Y) coordinate of the top left point, in inches, of the highlighted region's rectangle, related to the current page.
Width
The width, in inches, of the highlighted region's rectangle, related to the current page.
Height
The height, in inches, of the highlighted region's rectangle, related to the current page.
RegionColor
A color object that defines the fill color of the newly added highlighted region.
FillMode
A member of the RegionFillMode enumeration. Specifies the fill mode used to combine the region fill color and the displayed area of the image covered by this region when highlighting.

Return Value

A unique region identifier of the newly added highlighted region. Please always use the GetStat method to determine if this method has been successful.
Remarks
To convert pixels to inches, the horizontal values of the region's rectangle (left, width) should be divided by the PageHorizontalResolution property, and the vertical values of the region's rectangle (right, height) should be divided by the PageVerticalResolution property.

Be aware that highlighted regions are redefined using both SearchText(String,Int32,Boolean) and SearchText(String,Int32,Boolean,Boolean) methods.

Example
How to define highlighted regions according to the searched text.
'We assume that the GdViewer1 control has been properly integrated.
If GdViewer1.DisplayFromFile("") = GdPictureStatus.OK Then
    Dim text_to_find As String = "GdPicture"
    Dim regID As Integer = 0, occurrence As Integer = 1
    Dim left As Double = 0, top As Double = 0, width As Double = 0, height As Double = 0
    'Removing previously defined regions, if any.
    GdViewer1.RemoveAllRegions()
    While GdViewer1.SearchText(GdViewer1.CurrentPage, text_to_find, occurrence, True, True, left, top, width, height)
        If GdViewer1.GetStat() = GdPictureStatus.OK Then
            regID = GdViewer1.AddRegion("", left, top, width, height, Color.FromArgb(255, 176, 224, 230), GdPicture14.WPF.GdViewer.RegionFillMode.Multiply)
            If GdViewer1.GetStat() = GdPictureStatus.OK Then
                GdViewer1.SetRegionName(regID, "Region" + regID.ToString())
                occurrence += 1
            Else
                Exit While
            End If
        Else
            Exit While
        End If
    End While
    If GdViewer1.GetStat() = GdPictureStatus.OK Then
        If GdViewer1.RegionCount() = 0 Then MessageBox.Show("The given text has not been found.", "GdViewer.AddRegion")
    Else
        MessageBox.Show("An error has occurred. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.AddRegion")
    End If
Else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.AddRegion")
End If
//We assume that the GdViewer1 control has been properly integrated.
if (GdViewer1.DisplayFromFile("") == GdPictureStatus.OK)
{
    string text_to_find = "GdPicture";
    int regID = 0, occurrence = 1;
    double left = 0, top = 0, width = 0, height = 0;
    //Removing previously defined regions, if any.
    GdViewer1.RemoveAllRegions();
    while (GdViewer1.SearchText(GdViewer1.CurrentPage, text_to_find, occurrence, true, true, ref left, ref top, ref width, ref height))
    {
        if (GdViewer1.GetStat() == GdPictureStatus.OK)
        {
            regID = GdViewer1.AddRegion("", left, top, width, height, Color.FromArgb(255, 176, 224, 230), GdPicture14.WPF.GdViewer.RegionFillMode.Multiply);
            if (GdViewer1.GetStat() == GdPictureStatus.OK)
            {
                GdViewer1.SetRegionName(regID, "Region" + regID.ToString());
                occurrence += 1;
            }
            else
                break;
        }
        else
            break;
    }
    if (GdViewer1.GetStat() == GdPictureStatus.OK)
    {
        if (GdViewer1.RegionCount() == 0)
            MessageBox.Show("The given text has not been found.", "GdViewer.AddRegion");
    }
    else
        MessageBox.Show("An error has occurred. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.AddRegion");
}
else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.AddRegion");
See Also

Reference

GdViewer Class
GdViewer Members
RegionCount Method
RemoveAllRegions Method
SearchText(String,Int32,Boolean) Method
SearchText(String,Int32,Boolean,Boolean) Method
SearchText(Int32,String,Int32,Boolean,Double,Double,Double,Double) Method
SearchText(Int32,String,Int32,Boolean,Boolean,Double,Double,Double,Double) Method
RegionEdited Event
RegionSelected Event