Share via


Strokes.StrokesEnumerator.Current Property

Gets the Stroke object in the Strokes collection to which the enumerator is pointing.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Syntax

'Declaration
Public ReadOnly Property Current As Stroke
'Usage
Dim instance As Strokes.StrokesEnumerator 
Dim value As Stroke 

value = instance.Current
public Stroke Current { get; }
public:
property Stroke^ Current {
    Stroke^ get ();
}
public function get Current () : Stroke

Property Value

Type: Microsoft.Ink.Stroke
The Stroke object in the Strokes collection to which the enumerator is pointing.

Remarks

After a Strokes.StrokesEnumerator enumerator is created, or after the Reset method is called, the MoveNext method must be called to advance the enumerator to the first element of the collection before reading the value of the Current property; otherwise, the Current property is undefined.

The Current property throws an exception if the last call to the MoveNext method returns false. If the last call to the MoveNext method returns false, the enumerator has reached the end of the Strokes collection.

The Current property does not move the position of the enumerator. Consecutive calls to the Current property return the same object until either the MoveNext or Reset method is called.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection—such as adding, modifying or deleting elements—the enumerator is irrecoverably invalidated. The next call to the MoveNext or Reset method throws an InvalidOperationException exception. If the collection is modified between calling the MoveNext method and calling the Current property, the Current property returns the element that it is set to, even if the enumerator is already invalidated.

Examples

These examples show two ways to enumerate the Strokes collection in order to retrieve each Stroke object contained in the collection. The Strokes collection is returned by the Ink.Strokes property.

This example obtains the IEnumerator for the Strokes collection, and uses it to traverse the collection.

Private Sub EnumerateStrokesWithEnumerator(ByVal mInk As Ink)
    ' access the Strokes property via using statement 
    ' to insure that the object mStrokes is disposed when finished 
    ' Otherwise, you will have a memory leak 
    Using mStrokes As Strokes = mInk.Strokes
        Dim mStrokesEnumerator As IEnumerator = mStrokes.GetEnumerator()
        mStrokesEnumerator.Reset()
        While (mStrokesEnumerator.MoveNext())
            Dim S As Stroke = DirectCast(mStrokesEnumerator.Current, Stroke)
            Me.listBoxStrokeId.Items.Add(S.Id)
        End While 
    End Using 
End Sub
private void EnumerateStrokesWithEnumerator(Ink mInk)
{
    // access the Strokes property via using statement 
    // to insure that the object mStrokes is disposed when finished 
    // Otherwise, you will have a memory leak 
    using (Strokes mStrokes = mInk.Strokes)
    {
        IEnumerator mStrokesEnumerator = mStrokes.GetEnumerator();
        mStrokesEnumerator.Reset();
        while (mStrokesEnumerator.MoveNext())
        {
            Stroke S = (Stroke)mStrokesEnumerator.Current;
            this.listBoxStrokeId.Items.Add(S.Id);
        }
    }
}

This example uses the foreach statement, which calls the GetEnumerator method in internal code that the compiler generates to support the statement.

Private Sub EnumerateStrokesWithForEach(ByVal mInk As Ink)
    ' access the Strokes property via using statement 
    ' to insure that the object mStrokes is disposed when finished 
    ' Otherwise, you will have a memory leak 
    Using mStrokes As Strokes = mInk.Strokes
        For Each S As Stroke In mStrokes
            Me.listBoxStrokeId.Items.Add(S.Id)
        Next 
    End Using 
End Sub
private void EnumerateStrokesWithForEach(Ink mInk)
{    
    // access the Strokes property via using statement 
    // to insure that the object mStrokes is disposed when finished 
    // Otherwise, you will have a memory leak 
    using (Strokes mStrokes = mInk.Strokes)
    {
        foreach (Stroke S in mStrokes)
        {
            this.listBoxStrokeId.Items.Add(S.Id);
        }
    }
}

Platforms

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

Strokes.StrokesEnumerator Class

Strokes.StrokesEnumerator Members

Microsoft.Ink Namespace

Strokes

Stroke

Strokes.StrokesEnumerator.MoveNext

Strokes.StrokesEnumerator.Reset

Other Resources

System.Collections.IEnumerator