次の方法で共有


InkCollectorMouseDownEventHandler デリゲート

InkCollector オブジェクトの MouseDown イベントを処理するメソッドを表します。

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

構文

'宣言
Public Delegate Sub InkCollectorMouseDownEventHandler ( _
    sender As Object, _
    e As CancelMouseEventArgs _
)
'使用
Dim instance As New InkCollectorMouseDownEventHandler(AddressOf HandlerMethod)
public delegate void InkCollectorMouseDownEventHandler(
    Object sender,
    CancelMouseEventArgs e
)
public delegate void InkCollectorMouseDownEventHandler(
    Object^ sender, 
    CancelMouseEventArgs^ e
)
/** @delegate */
public delegate void InkCollectorMouseDownEventHandler(
    Object sender,
    CancelMouseEventArgs e
)
JScript では、デリゲートは使用できません。

パラメータ

解説

InkCollectorMouseDownEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを指定します。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。パフォーマンス上の理由から、マネージ コードでは既定のイベント対象は無効ですが、イベント ハンドラを追加すると自動的に有効になります。

リアルタイムのインク パフォーマンスを向上するために、インク処理中にマウス カーソルを非表示にします。そのためには、MouseDown イベント ハンドラのマウス カーソルを非表示にし、MouseUp イベント ハンドラのマウス カーソルを表示します。

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

一部のコントロールは、MouseDownMouseMove、および MouseUp イベント間の特定のリレーションシップに依存しています。これらのイベントをキャンセルした場合、予期せぬ結果が生じる可能性があります。

この例では、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

参照

参照

Microsoft.Ink 名前空間

InkCollector.MouseMove

InkCollector.MouseUp

InkCollector.MouseWheel