Reference Guide
GdPicture14 Namespace / GdViewer Class / AddRegion Method / AddRegion(String,Int32,Int32,Int32,Int32,ForegroundMixMode,Int32) Method
The name of the newly added highlighted region. It can be an empty string.
The horizontal (X) coordinate (0-based) of the top left point, in pixels, of the highlighted region's rectangle, related to the current page.
The vertical (Y) coordinate (0-based) of the top left point, in pixels, of the highlighted region's rectangle, related to the current page.
The width, in pixels, of the highlighted region's rectangle, related to the current page.
The height, in pixels, of the highlighted region's rectangle, related to the current page.
A member of the ForegroundMixMode enumeration. Specifies the foreground mix mode used to combine the region fill color and the displayed area of the image covered by this region when highlighting.
A color value that defines the fill color of the newly added highlighted region. You can obtain a suitable color using the ARGBI method.
Example





In This Topic
    AddRegion(String,Int32,Int32,Int32,Int32,ForegroundMixMode,Int32) Method
    In This Topic
    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 pixels 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 several events related to highlighted regions like RegionEditedByUser, RegionMovedByUser , RegionResizedByUser and RegionSelectedByUser.

    Syntax
    'Declaration
     
    
    Public Overloads Function AddRegion( _
       ByVal Name As String, _
       ByVal Left As Integer, _
       ByVal Top As Integer, _
       ByVal Width As Integer, _
       ByVal Height As Integer, _
       ByVal MixMode As ForegroundMixMode, _
       ByVal RegionColor As Integer _
    ) As Integer
    public int AddRegion( 
       string Name,
       int Left,
       int Top,
       int Width,
       int Height,
       ForegroundMixMode MixMode,
       int RegionColor
    )
    public function AddRegion( 
        Name: String;
        Left: Integer;
        Top: Integer;
        Width: Integer;
        Height: Integer;
        MixMode: ForegroundMixMode;
        RegionColor: Integer
    ): Integer; 
    public function AddRegion( 
       Name : String,
       Left : int,
       Top : int,
       Width : int,
       Height : int,
       MixMode : ForegroundMixMode,
       RegionColor : int
    ) : int;
    public: int AddRegion( 
       string* Name,
       int Left,
       int Top,
       int Width,
       int Height,
       ForegroundMixMode MixMode,
       int RegionColor
    ) 
    public:
    int AddRegion( 
       String^ Name,
       int Left,
       int Top,
       int Width,
       int Height,
       ForegroundMixMode MixMode,
       int RegionColor
    ) 

    Parameters

    Name
    The name of the newly added highlighted region. It can be an empty string.
    Left
    The horizontal (X) coordinate (0-based) of the top left point, in pixels, of the highlighted region's rectangle, related to the current page.
    Top
    The vertical (Y) coordinate (0-based) of the top left point, in pixels, of the highlighted region's rectangle, related to the current page.
    Width
    The width, in pixels, of the highlighted region's rectangle, related to the current page.
    Height
    The height, in pixels, of the highlighted region's rectangle, related to the current page.
    MixMode
    A member of the ForegroundMixMode enumeration. Specifies the foreground mix mode used to combine the region fill color and the displayed area of the image covered by this region when highlighting.
    RegionColor
    A color value that defines the fill color of the newly added highlighted region. You can obtain a suitable color using the ARGBI method.

    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
    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 Single = 0, top As Single = 0, width As Single = 0, height As Single = 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
                //The coordinates and sizes are simply translated to pixels.
                regID = GdViewer1.AddRegion("", left * 96, top * 96, width * 96, height * 96, ForegroundMixMode.ForegroundMixModeMASKPEN, GdViewer1.ARGBI(255, 176, 224, 230))
                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;
        float 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)
            {
                //The coordinates and sizes are simply translated to pixels.
                regID = GdViewer1.AddRegion("", (int)(left * 96), (int)(top * 96), (int)(width * 96), (int)(height * 96), ForegroundMixMode.ForegroundMixModeMASKPEN, GdViewer1.ARGBI(255, 176, 224, 230));
                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