IncrementalHitTester クラス

定義

Strokeでヒット テストを動的に実行します。

public ref class IncrementalHitTester abstract
public abstract class IncrementalHitTester
type IncrementalHitTester = class
Public MustInherit Class IncrementalHitTester
継承
IncrementalHitTester
派生

次の例では、ユーザーがスタイラスを使用してデータを入力するときに、 IncrementalHitTester にポイントを追加する方法を示します。 この例には、ユーザーが交差するStrokeの部分を消去するStrokeHit イベント ハンドラーが含まれています。 ユーザーがインクを消去できるようにするコントロールを作成するには、「 方法: カスタム コントロールでインクを消去する」を参照してください。


// 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から継承する 2 つのクラスがあります。

  • IncrementalLassoHitTesterヒット テストでは、なげなわパスがストロークを囲むかどうかを判断します。

  • IncrementalStrokeHitTesterヒット テストでは、消しゴム パスが交差する場所を決定することによってストロークがテストされます。

次の表に、カスタム コントロールでデジタル インクを管理する方法を示します。

これを行うには この記事を参照してください
デジタル インクを収集するコントロールを作成する インク入力コントロールの作成
ユーザーがインクを選択できるようにするコントロールを作成する 方法: カスタム コントロールからインクを選択する
ユーザーがインクをポイント消去できるようにするコントロールを作成する 方法: カスタム コントロールのインクを消去する

XAML テキストの使用法

通常、このクラスは XAML では使用されません。

プロパティ

名前 説明
IsValid

IncrementalHitTesterがヒット テストであるかどうかを取得します。

メソッド

名前 説明
AddPoint(Point)

PointIncrementalHitTesterを追加します。

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)

適用対象