Ink.DeleteStrokes 方法 (Strokes)

Ink 对象删除指定的 Strokes 集合。

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

语法

声明
Public Sub DeleteStrokes ( _
    strokes As Strokes _
)
用法
Dim instance As Ink
Dim strokes As Strokes

instance.DeleteStrokes(strokes)
public void DeleteStrokes(
    Strokes strokes
)
public:
void DeleteStrokes(
    Strokes^ strokes
)
public void DeleteStrokes(
    Strokes strokes
)
public function DeleteStrokes(
    strokes : Strokes
)

参数

备注

如果删除的 Stroke 对象不在 Ink 对象的 Strokes 集合的末尾,则 Ink 对象重新确定 Ink 对象中剩余 Stroke 对象的索引。

如果在用户主动绘制墨迹 时调用,DeleteStrokes 方法将导致错误。

备注

如果从 Ink 对象删除原始集合中包含的 Stroke 对象,则指向 Ink.Strokes 属性的 Strokes 集合将无效。例如,如果有一个命名 Strokes 集合 theStrokesToo 基于 Ink 对象的 Strokes 属性 theStrokes,并且对 theStrokes 调用 DeleteStrokes 方法,则 theStrokesToo 将无效。

若要一次仅删除一个 Stroke 对象,请调用 DeleteStroke 方法。

示例

此示例包含一个示例函数,该函数删除传递的 InkOverlay 对象中所有在参数 LeftInPixels 左侧(像素空间中)包含 PointStroke 对象。

Private Sub DeleteStrokesByLeft(ByVal mInkOverlay As InkOverlay, ByVal LeftInPixels As Integer)
    ' Create a Point object based upon the Left parameter
    Dim ptLeft As Point = New Point(LeftInPixels, 0)

    ' Convert the point from pixel space to ink space dimensions
    ' InkOverlay.AttachedControl must be set
    Using g As Graphics = mInkOverlay.AttachedControl.CreateGraphics()
        mInkOverlay.Renderer.PixelToInkSpace(g, ptLeft)
    End Using

    ' Create a Strokes object to hold strokes to be deleted
    Dim strokesToDelete As Strokes = mInkOverlay.Ink.CreateStrokes()

    ' Access to the Strokes property returns a copy of the Strokes object.
    ' This copy must be implicitly (via using statement) or explicitly
    ' disposed of in order to avoid a memory leak.
    Using currentStrokes As Strokes = mInkOverlay.Ink.Strokes
        For Each S As Stroke In currentStrokes
            For Each strokePoint As Point In S.GetPoints()
                If (strokePoint.X < ptLeft.X) Then
                    ' Note: A particluar Stroke object might have several
                    ' points to the left of ptLeft.X - Therefore, the
                    ' following statement will be executed multiple times.
                    ' Even so, the Add method will not add the same stroke twice. 
                    strokesToDelete.Add(S)
                End If
            Next
        Next
    End Using
    If strokesToDelete.Count > 0 Then
        mInkOverlay.Ink.DeleteStrokes(strokesToDelete)
        mInkOverlay.AttachedControl.Invalidate()
    End If
    strokesToDelete.Dispose()
End Sub
private void DeleteStrokesByLeft(InkOverlay mInkOverlay, int LeftInPixels)
{
    // Create a Point object based upon the Left parameter
    Point ptLeft = new Point(LeftInPixels, 0);

    // Convert the point from pixel space to ink space dimensions
    // InkOverlay.AttachedControl must be set
    using (Graphics g = mInkOverlay.AttachedControl.CreateGraphics())
    {
        mInkOverlay.Renderer.PixelToInkSpace(g, ref ptLeft);
    }

    // Create a Strokes object to hold strokes to be deleted
    Strokes strokesToDelete = mInkOverlay.Ink.CreateStrokes();

    // Access to the Strokes property returns a copy of the Strokes object.
    // This copy must be implicitly (via using statement) or explicitly
    // disposed of in order to avoid a memory leak.
    using (Strokes currentStrokes = mInkOverlay.Ink.Strokes)
    {
        foreach (Stroke S in currentStrokes)
        {
            foreach (Point strokePoint in S.GetPoints())
            {
                if (strokePoint.X < ptLeft.X)
                {
                    // Note: A particluar Stroke object might have several
                    // points to the left of ptLeft.X - Therefore, the
                    // following statement will be executed multiple times.
                    // Even so, the Add method will not add the same stroke twice. 
                    strokesToDelete.Add(S);
                }
            }
        }
    }

    if (strokesToDelete.Count > 0)
    {
        mInkOverlay.Ink.DeleteStrokes(strokesToDelete);
        mInkOverlay.AttachedControl.Invalidate();
    }
    strokesToDelete.Dispose();
}

平台

Windows Vista

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

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

Ink 类

Ink 成员

DeleteStrokes 重载

Microsoft.Ink 命名空间

Strokes

Ink.DeleteStroke

Ink.CreateStroke

Ink.CreateStrokes