AddRegion(String,Double,Double,Double,Double,Color,RegionFillMode) 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 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 As String, _
ByVal As Double, _
ByVal As Double, _
ByVal As Double, _
ByVal As Double, _
ByVal As Color, _
ByVal As GdViewer.RegionFillMode _
) As Integer
public int AddRegion(
string ,
double ,
double ,
double ,
double ,
Color ,
GdViewer.RegionFillMode
)
public function AddRegion(
: String;
: Double;
: Double;
: Double;
: Double;
: Color;
: GdViewer.RegionFillMode
): Integer;
public function AddRegion(
: String,
: double,
: double,
: double,
: double,
: Color,
: GdViewer.RegionFillMode
) : int;
public: int AddRegion(
string* ,
double ,
double ,
double ,
double ,
Color ,
GdViewer.RegionFillMode
)
public:
int AddRegion(
String^ ,
double ,
double ,
double ,
double ,
Color ,
GdViewer.RegionFillMode
)
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. The
GetStat method can be subsequently used to determine if this method has been successful.
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");
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
SearchText(String,Int32,Boolean) Method
SearchText(String,Int32,Boolean,Boolean) Method
RegionEdited Event
RegionSelected Event
PreviewRegionEdited Event
PreviewRegionSelected Event
PageHorizontalResolution Property
PageVerticalResolution Property
SearchText(String,Int32,Boolean) Method
SearchText(String,Int32,Boolean,Boolean) Method
GetStat Method
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