GdPicture.NET.14
GdPicture14 Namespace / GdViewer Class / GetSelectedAnnotationIdx Method
Example





In This Topic
GetSelectedAnnotationIdx Method (GdViewer)
In This Topic
Returns an index of the selected GdPicture/XMP annotation object within the current page of the document displayed in the GdViewer control.

Be aware that this method only handles GdPicture/XMP annotations. Likewise, annotations are always treated relative to the currently displayed page.

Syntax
'Declaration
 
Public Function GetSelectedAnnotationIdx() As Integer
public int GetSelectedAnnotationIdx()
public function GetSelectedAnnotationIdx(): Integer; 
public function GetSelectedAnnotationIdx() : int;
public: int GetSelectedAnnotationIdx(); 
public:
int GetSelectedAnnotationIdx(); 

Return Value

An index of the selected GdPicture/XMP annotation object. The returned value is between 0 and GetAnnotationCount-1 if some annotation is selected or -1 if none is selected.

Be aware that this method does not set the error status if no annotation is selected.

Remarks
Please ensure that the returned value is valid annotation index, which means it is greater then -1, before using it further. The reason is that this method does not set the error status if no annotation is selected.

The method only handles GdPicture/XMP annotations as well.

Be aware that annotations are always treated relative to the currently displayed page.

Example
How to properly retrieve the selected annotation, if any.
'We assume that the GdViewer1 control has been properly integrated
'and your document has been properly displayed as well.
Dim annotIdx As Integer = GdViewer1.GetSelectedAnnotationIdx()
If annotIdx >= 0 Then
    Dim annot As GdPicture14.Annotations.Annotation = GdViewer1.GetAnnotationFromIdx(annotIdx)
    If GdViewer1.GetStat() <> GdPictureStatus.OK Then Throw New IndexOutOfRangeException()
    MessageBox.Show("The index of the selected annotation is: " + annotIdx + vbCrLf +
                    "  Author: " + annot.Author + "  Created: " + annot.CreationTime.ToString() + "  Subject: " + annot.Subject, "GdViewer.GetSelectedAnnotationIdx")
Else
    MessageBox.Show("No annotation is currently selected.", "GdViewer.GetSelectedAnnotationIdx")
End If
//We assume that the GdViewer1 control has been properly integrated
//and your document has been properly displayed as well.
int annotIdx = GdViewer1.GetSelectedAnnotationIdx();
if (annotIdx >= 0)
{
    GdPicture14.Annotations.Annotation annot = GdViewer1.GetAnnotationFromIdx(annotIdx);
    if (GdViewer1.GetStat() != GdPictureStatus.OK) throw new IndexOutOfRangeException();
    MessageBox.Show("The index of the selected annotation is: " + annotIdx +
                    "\n  Author: " + annot.Author + "  Created: " + annot.CreationTime + "  Subject: " + annot.Subject, "GdViewer.GetSelectedAnnotationIdx");
}
else
{
    MessageBox.Show("No annotation is currently selected.", "GdViewer.GetSelectedAnnotationIdx");
}
See Also