共用方式為


IncrementalHitTester 類別

定義

動態對 Stroke 執行點擊測試 (Hit Testing)。

public ref class IncrementalHitTester abstract
public abstract class IncrementalHitTester
type IncrementalHitTester = class
Public MustInherit Class IncrementalHitTester
繼承
IncrementalHitTester
衍生

範例

下列範例示範如何在使用者以手寫筆輸入資料時,將點新增至 IncrementalHitTester 。 此範例包含 StrokeHit 事件處理常式,可清除使用者交集的 Stroke 部分。 若要建立可讓使用者清除筆跡的控制項,請參閱 How to: Erase Ink on a Custom Control


// Prepare to collect stylus packets. Get the 
// IncrementalHitTester from the InkPresenter's 
// StrokeCollection and subscribe to its StrokeHitChanged event.
protected override void OnStylusDown(StylusDownEventArgs e)
{
    base.OnStylusDown(e);

    EllipseStylusShape eraserTip = new EllipseStylusShape(3, 3, 0);
    eraseTester = 
        presenter.Strokes.GetIncrementalStrokeHitTester(eraserTip);
    eraseTester.StrokeHit += new StrokeHitEventHandler(eraseTester_StrokeHit);
    eraseTester.AddPoints(e.GetStylusPoints(this));
}

// Collect the StylusPackets as the stylus moves.
protected override void OnStylusMove(StylusEventArgs e)
{
    if (eraseTester.IsValid)
    {
        eraseTester.AddPoints(e.GetStylusPoints(this));
    }
}

// Unsubscribe from the StrokeHitChanged event when the
// user lifts the stylus.
protected override void OnStylusUp(StylusEventArgs e)
{

    eraseTester.AddPoints(e.GetStylusPoints(this));
    eraseTester.StrokeHit -= new
        StrokeHitEventHandler(eraseTester_StrokeHit);
    eraseTester.EndHitTesting();
}

// When the stylus intersects a stroke, erase that part of
// the stroke.  When the stylus dissects a stoke, the 
// Stroke.Erase method returns a StrokeCollection that contains
// the two new strokes.
void eraseTester_StrokeHit(object sender,
    StrokeHitEventArgs args)
{
    StrokeCollection eraseResult =
        args.GetPointEraseResults();
    StrokeCollection strokesToReplace = new StrokeCollection();
    strokesToReplace.Add(args.HitStroke);
   
    // Replace the old stroke with the new one.
    if (eraseResult.Count > 0)
    {
        presenter.Strokes.Replace(strokesToReplace, eraseResult);
    }
    else
    {
        presenter.Strokes.Remove(strokesToReplace);
    }
}

     ' Prepare to collect stylus packets. Get the 
     ' IncrementalHitTester from the InkPresenter's 
     ' StrokeCollection and subscribe to its StrokeHitChanged event.
     Protected Overrides Sub OnStylusDown(ByVal e As StylusDownEventArgs)

         MyBase.OnStylusDown(e)

         Dim eraserTip As New EllipseStylusShape(3, 3, 0)
         eraseTester = presenter.Strokes.GetIncrementalStrokeHitTester(eraserTip)
         AddHandler eraseTester.StrokeHit, _
             AddressOf eraseTester_StrokeHit
         eraseTester.AddPoints(e.GetStylusPoints(Me))

     End Sub

     ' Collect the StylusPackets as the stylus moves.
     Protected Overrides Sub OnStylusMove(ByVal e As StylusEventArgs)

         If eraseTester.IsValid Then
             eraseTester.AddPoints(e.GetStylusPoints(Me))
         End If

     End Sub

     ' Unsubscribe from the StrokeHitChanged event when the
     ' user lifts the stylus.
     Protected Overrides Sub OnStylusUp(ByVal e As StylusEventArgs)

         eraseTester.AddPoints(e.GetStylusPoints(Me))

         RemoveHandler eraseTester.StrokeHit, _
             AddressOf eraseTester_StrokeHit
         eraseTester.EndHitTesting()

     End Sub


     ' When the stylus intersects a stroke, erase that part of
     ' the stroke.  When the stylus dissects a stoke, the 
     ' Stroke.Erase method returns a StrokeCollection that contains
     ' the two new strokes.
     Private Sub eraseTester_StrokeHit(ByVal sender As Object, _
             ByVal args As StrokeHitEventArgs)

         Dim eraseResult As StrokeCollection = _
             args.GetPointEraseResults()
         Dim strokesToReplace As New StrokeCollection()
         strokesToReplace.Add(args.HitStroke)

         ' Replace the old stroke with the new one.
         If eraseResult.Count > 0 Then
             presenter.Strokes.Replace(strokesToReplace, eraseResult)
         Else
             presenter.Strokes.Remove(strokesToReplace)
         End If

     End Sub

備註

IncrementalHitTester 動態判斷使用者是否「點擊」。 Stroke 此類別可讓您在選取和清除筆跡等情況下,立即向使用者提供意見反應。

繼承自 IncrementalHitTester 的類別有兩個:

下表列出如何管理自訂控制項上的數位筆跡的位置。

若要進行此動作... 請參閱此文章
建立可收集數位筆跡的控制項 建立筆墨輸入控制項
建立可讓使用者選取筆跡的控制項 如何:從自訂控制項選取筆墨
建立可讓使用者點清除筆跡的控制項 如何:清除自訂控制項上的筆墨

XAML 文字使用方式

這個類別通常不會在 XAML 中使用。

屬性

IsValid

取得值,指出 IncrementalHitTester 是否正在進行點擊測試。

方法

AddPoint(Point)

Point 加入至 IncrementalHitTester

AddPoints(IEnumerable<Point>)

將點加入 IncrementalHitTester

AddPoints(StylusPointCollection)

將指定的 StylusPoint 物件加入至 IncrementalHitTester 中。

AddPointsCore(IEnumerable<Point>)

將點加入 IncrementalHitTester

EndHitTesting()

釋出 IncrementalHitTester 所使用的資源。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於