Strokes.GetEnumerator 方法

返回一个对象,该对象实现 IEnumerator 接口并可以循环访问 Strokes 集合中的 Stroke 对象。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public Function GetEnumerator As Strokes..::.StrokesEnumerator
用法
Dim instance As Strokes
Dim returnValue As Strokes..::.StrokesEnumerator

returnValue = instance.GetEnumerator()
public Strokes..::.StrokesEnumerator GetEnumerator()
public:
Strokes..::.StrokesEnumerator^ GetEnumerator()
public Strokes..::.StrokesEnumerator GetEnumerator()
public function GetEnumerator() : Strokes..::.StrokesEnumerator

返回值

类型:Microsoft.Ink.Strokes.StrokesEnumerator
返回一个对象,该对象实现 IEnumerator 接口并可以循环访问 Strokes 集合中的 Stroke 对象。

示例

这些示例演示两种枚举 Strokes 集合以检索集合中包含的每个 Stroke 对象的方法。Strokes 集合由 Ink.Strokes 属性返回。

此示例获取 Strokes 集合的 IEnumerator,然后使用它遍历该集合。

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);
        }
    }
}

此示例使用 foreach 语句,该语句调用内部代码中的 GetEnumerator 方法,该方法是编译器为支持此语句而生成的。

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);
        }
    }
}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

Strokes 类

Strokes 成员

Microsoft.Ink 命名空间

Stroke

Ink.Strokes