次の方法で共有


InkOverlay.HitTestSelection メソッド

ヒット テストでヒットした選択部分 (存在する場合) を示す値を返します。

名前空間 :  Microsoft.Ink
アセンブリ :  Microsoft.Ink (Microsoft.Ink.dll 内)

構文

'宣言
Public Function HitTestSelection ( _
    X As Integer, _
    Y As Integer _
) As SelectionHitResult
'使用
Dim instance As InkOverlay
Dim X As Integer
Dim Y As Integer
Dim returnValue As SelectionHitResult

returnValue = instance.HitTestSelection(X, _
    Y)
public SelectionHitResult HitTestSelection(
    int X,
    int Y
)
public:
SelectionHitResult HitTestSelection(
    int X, 
    int Y
)
public SelectionHitResult HitTestSelection(
    int X,
    int Y
)
public function HitTestSelection(
    X : int, 
    Y : int
) : SelectionHitResult

パラメータ

  • X
    型 : System.Int32
    ヒット テストの x 位置 (ピクセル単位)
  • Y
    型 : System.Int32
    ヒット テストの y 位置 (ピクセル単位)

戻り値

型 : Microsoft.Ink.SelectionHitResult
ヒット テストでヒットした選択部分 (存在する場合) を指定する SelectionHitResult 列挙体のメンバ。

解説

このメソッドは、InkOverlay.EditingMode プロパティが Select に設定されている場合にのみ役立ちます。

ms569279.alert_note(ja-jp,VS.90).gifメモ :

120dpi に設定された Windows XP デスクトップ コンピュータでインク アプリケーションを実行する場合、指定したポイントがインク空間からピクセル空間に変換されると、HitTestSelection メソッドがスケール ファクタにより無効になります。

この例では、MouseDown イベントが発生するときに、EditingModeSelect に設定されているかどうかを確認するチェックが行われます。設定されている場合は、HitTestSelection メソッドが呼び出され、選択のどの部分 (ある場合) がヒットしたかが判断されます。4 つの主要なコンパス方位のいずれかでヒットした場合は、SelectionHitResult 列挙体で指定されたとおり、選択されているストローク オブジェクトが別の色に変更されます。

Private Sub mInkObject_MouseDown(ByVal sender As Object, ByVal e As CancelMouseEventArgs)

    If InkOverlayEditingMode.Select = mInkObject.EditingMode Then
        Select Case mInkObject.HitTestSelection(e.X, e.Y)
            Case SelectionHitResult.North
                ChangeSelectionColor(Color.Green)
            Case SelectionHitResult.East
                ChangeSelectionColor(Color.Red)
            Case SelectionHitResult.South
                ChangeSelectionColor(Color.Purple)
            Case SelectionHitResult.West
                ChangeSelectionColor(Color.Blue)
        End Select
    End If
End Sub

Private Sub ChangeSelectionColor(ByVal color As Color)
    Dim DA As DrawingAttributes = mInkObject.DefaultDrawingAttributes.Clone()
    DA.Color = color
    mInkObject.Selection.ModifyDrawingAttributes(DA)
    Using G As Graphics = CreateGraphics()
        ' Get the bounding box of the selection. The default is
        ' to include the width of the strokes in the calculation.
        ' The returned rectangle is measured in ink units.
        Dim rInkUnits As Rectangle = mInkObject.Selection.GetBoundingBox()

        ' In selection mode, the selected strokes are drawn inflated
        ' GetBoundingBox() does not take this into account
        ' Rectangle rInkUnits is inflated to compensate
        rInkUnits.Inflate(53, 53)

        Dim topLeft As Point = rInkUnits.Location
        Dim bottomRight As Point = rInkUnits.Location + rInkUnits.Size

        ' get a Renderer object to make the conversion
        Dim R As Renderer = New Renderer()

        ' convert the points to pixels
        R.InkSpaceToPixel(G, topLeft)
        R.InkSpaceToPixel(G, bottomRight)

        ' create a rectangle that is in pixels
        Dim rPixelUnits As Rectangle = _
            New Rectangle(topLeft, New Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y))

        ' Redraw the strokes
        mInkObject.Draw(rPixelUnits)

    End Using
End Sub
private void mInkObject_MouseDown(object sender, CancelMouseEventArgs e)
{
    if (InkOverlayEditingMode.Select == mInkObject.EditingMode)
    {
        switch (mInkObject.HitTestSelection(e.X, e.Y))
        {
            case SelectionHitResult.North:
                ChangeSelectionColor(Color.Green);
                break;
            case SelectionHitResult.East:
                ChangeSelectionColor(Color.Red);
                break;
            case SelectionHitResult.South:
                ChangeSelectionColor(Color.Purple);
                break;
            case SelectionHitResult.West:
                ChangeSelectionColor(Color.Blue);
                break;
        }
    }
}

private void ChangeSelectionColor(Color color)
{
    DrawingAttributes DA = mInkObject.DefaultDrawingAttributes.Clone();
    DA.Color = color;
    mInkObject.Selection.ModifyDrawingAttributes(DA);
    using (Graphics G = CreateGraphics())
    {
        // Get the bounding box of the selection. The default is
        // to include the width of the strokes in the calculation.
        // The returned rectangle is measured in ink units.
        Rectangle rInkUnits = mInkObject.Selection.GetBoundingBox();

        // In selection mode, the selected strokes are drawn inflated
        // GetBoundingBox() does not take this into account
        // Rectangle rInkUnits is inflated to compensate
        rInkUnits.Inflate(53, 53);

        Point topLeft = rInkUnits.Location;
        Point bottomRight = rInkUnits.Location + rInkUnits.Size;

        // get a Renderer object to make the conversion
        Renderer R = new Renderer();

        // convert the points to pixels
        R.InkSpaceToPixel(G, ref topLeft);
        R.InkSpaceToPixel(G, ref bottomRight);

        // create a rectangle that is in pixels
        Rectangle rPixelUnits =
            new Rectangle(topLeft, new Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y));

        // Redraw the strokes
        mInkObject.Draw(rPixelUnits);

    } 
}

プラットフォーム

Windows Vista

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 3.0

参照

参照

InkOverlay クラス

InkOverlay メンバ

Microsoft.Ink 名前空間

SelectionHitResult