GdPicture.NET.14
GdPicture14 Namespace / GdViewer Class / SetRegionName Method
A unique region identifier of the specified region. You can obtain this identifier using the GetRegionID method or when creating regions using AddRegion(String,Int32,Int32,Int32,Int32,ForegroundMixMode,Int32) or AddRegionInches(String,Single,Single,Single,Single,ForegroundMixMode,Int32) methods.
The new name of the specified region.
Example





In This Topic
SetRegionName Method (GdViewer)
In This Topic
Sets the name of a highlighted region specified by its unique identifier related to the document currently displayed in the GdViewer control. These regions, if present, determines the currently defined highlighted regions on the displayed document.

You can define the name of each highlighted region when adding regions using AddRegion(String,Int32,Int32,Int32,Int32,ForegroundMixMode,Int32) or AddRegionInches(String,Single,Single,Single,Single,ForegroundMixMode,Int32) methods. You can determine the name of each highlighted region using the GetRegionName method.

Syntax
'Declaration
 
Public Function SetRegionName( _
   ByVal RegionID As Integer, _
   ByVal Name As String _
) As GdPictureStatus
public GdPictureStatus SetRegionName( 
   int RegionID,
   string Name
)
public function SetRegionName( 
    RegionID: Integer;
    Name: String
): GdPictureStatus; 
public function SetRegionName( 
   RegionID : int,
   Name : String
) : GdPictureStatus;
public: GdPictureStatus SetRegionName( 
   int RegionID,
   string* Name
) 
public:
GdPictureStatus SetRegionName( 
   int RegionID,
   String^ Name
) 

Parameters

RegionID
A unique region identifier of the specified region. You can obtain this identifier using the GetRegionID method or when creating regions using AddRegion(String,Int32,Int32,Int32,Int32,ForegroundMixMode,Int32) or AddRegionInches(String,Single,Single,Single,Single,ForegroundMixMode,Int32) methods.
Name
The new name of the specified region.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK. We strongly recommend always checking this status first.
Remarks
Be aware that if the required region does not exist, the method will fail.

Just to inform you, that the default region name set by the toolkit is "SearchRegion"+occurrence_number when defining regions by using SearchText(String,Int32,Boolean) methods.

Example
Both these examples show you how to set a name to a defined highlighted region.
This example demonstrates how to assign the custom name to a newly added region.
'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
            regID = GdViewer1.AddRegionInches("", left, top, width, height, 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.SetRegionName")
    Else
        MessageBox.Show("An error has occurred. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SetRegionName")
    End If
Else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SetRegionName")
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)
        {
            regID = GdViewer1.AddRegionInches("", left, top, width, height, 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.SetRegionName");
    }
    else
        MessageBox.Show("An error has occurred. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SetRegionName");
}
else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SetRegionName");
This example outlines how to rename the highlighted region using its unique idetifier.
'We assume that the GdViewer1 control has been properly integrated and your document has been properly displayed as well.
            
'To successfully follow this example, please use the code snippet attached to AddRegion or AddRegionInches methods
'to define highlighted regions or define some highlighted regions using SearchText methods by yourself.
Dim regID As Integer = 0, regCount As Integer = GdViewer1.RegionCount()
If regCount > 0 Then
    Dim message As String = "The number of regions: " + regCount.ToString()
    For j As Integer = 1 To regCount
        regID = GdViewer1.GetRegionID(j)
        message = message + vbCrLf + "regID: " + regID.ToString() + "  prev.name: " + GdViewer1.GetRegionName(regID) + "  current name: "
        GdViewer1.SetRegionName(regID, "Region" + regID.ToString())
        message += GdViewer1.GetRegionName(regID)
    Next
    MessageBox.Show(message, "GdViewer.SetRegionName")
Else
    MessageBox.Show("No highlighted region found related to this document. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SetRegionName")
End If
//We assume that the GdViewer1 control has been properly integrated and your document has been properly displayed as well.
            
//To successfully follow this example, please use the code snippet attached to AddRegion or AddRegionInches methods
//to define highlighted regions or define some highlighted regions using SearchText methods by yourself.
int regID = 0, regCount = GdViewer1.RegionCount();
if (regCount > 0)
{
    string message = "The number of regions: " + regCount.ToString();
    for (int j = 1; j <= regCount; j++)
    {
        regID = GdViewer1.GetRegionID(j);
        message = message + "\nregID: " + regID.ToString() + "  prev.name: " + GdViewer1.GetRegionName(regID) + "  current name: ";
        GdViewer1.SetRegionName(regID, "Region" + regID.ToString());
        message += GdViewer1.GetRegionName(regID);
    }
    MessageBox.Show(message, "GdViewer.SetRegionName");
}
else
    MessageBox.Show("No highlighted region found related to this document. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SetRegionName");
See Also