InkOverlay.HitTestSelection Method

InkOverlay.HitTestSelection Method

Returns a value that indicates which part of a selection, if any, was hit during a hit test.

Definition

Visual Basic .NET Public Function HitTestSelection( _
ByVal X As Integer, _
ByVal Y As Integer _
) As SelectionHitResult
C# public SelectionHitResult HitTestSelection(
int X,
int Y
);
Managed C++ public: SelectionHitResult* HitTestSelection(
int *X,
int *Y
);

Parameters

X System.Int32. The x-position, in pixels, of the hit test.
Y System.Int32. The y-position, in pixels, of the hit test.

Return Value

Microsoft.Ink.SelectionHitResult. A member of the SelectionHitResult enumeration, which specifies which part of a selection, if any, was hit during a hit test.

None
0
Specifies no part of the selection was hit.
Northwest
1
Specifies the northwest corner sizing handle was hit.
Southeast
2
Specifies the southeast corner sizing handle was hit.
Northeast
3
Specifies the northeast corner sizing handle was hit.
Southwest
4
Specifies the southwest corner sizing handle was hit.
East
5
Specifies the east side sizing handle was hit.
West
6
Specifies the west side sizing handle was hit.
North
7
Specifies the north side sizing handle was hit.
South
8
Specifies the south side sizing handle was hit.
Selection
9
Specifies the selection itself was hit (no selection handle was hit).

Exceptions

ObjectDisposedException Leave Site: The InkOverlay object is disposed.

Remarks

This method is only useful if the InkOverlay.EditingMode property is set to Select.

Examples

[C#]

This C# example uses a check box, theCheckBox, to toggle an InkOverlay object, theInkOverlay, between inking and selection modes, and uses the results from the HitTestSelection method to change the color of the selection when a user clicks one of the sizing handles of the selection rectangle.


using System;
using System.Windows.Forms;
using Microsoft.Ink;

namespace theApplication
{
    public class Form1: System.Windows.Forms.Form
    {
        private Microsoft.Ink.InkOverlay theInkOverlay;
        private System.Windows.Forms.CheckBox theCheckBox;

        public Form1()
        {
            InitializeComponent();

            theInkOverlay = new InkOverlay(Handle);
            // Behind attach mode allows you to use the check box.
            theInkOverlay.AttachMode = InkOverlayAttachMode.Behind;
            theInkOverlay.Enabled = true;
        }

        private void InitializeComponent()
        {
            this.theCheckBox = new System.Windows.Forms.CheckBox();
            this.SuspendLayout();
            //
            // theCheckBox
            //
            this.theCheckBox.Name = "theCheckBox";
            this.theCheckBox.TabIndex = 0;
            this.theCheckBox.Text = "Selection Mode";
            this.theCheckBox.CheckedChanged += new System.EventHandler(this.theCheckBox_CheckedChanged);
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(304, 266);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.theCheckBox});
            this.Name = "Form1";
            this.Text = "HitTestSelection";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }

        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }

        // Create the InkOverlay, add the mouse down event handler, and enable the InkOverlay
        private void Form1_Load(object sender, System.EventArgs e)
        {
            theInkOverlay.MouseDown += new InkCollectorMouseDownEventHandler(theInkOverlay_MouseDown);
        }

        // Handle the mouse down event for the InkOverlay
        private void theInkOverlay_MouseDown(object sender, CancelMouseEventArgs e)
        {
            if (theInkOverlay.EditingMode == InkOverlayEditingMode.Select)
            {
                SelectionHitResult result = theInkOverlay.HitTestSelection(e.X, e.Y);
                DrawingAttributes theDrawingAttributes = new DrawingAttributes();
                if (result == SelectionHitResult.Northwest)
                {
                    theDrawingAttributes.Color = System.Drawing.Color.Green;
                }
                else if (result == SelectionHitResult.Northeast)
                {
                    theDrawingAttributes.Color = System.Drawing.Color.Red;
                }
                else if (result == SelectionHitResult.Southeast)
                {
                    theDrawingAttributes.Color = System.Drawing.Color.Yellow;
                }
                else if (result == SelectionHitResult.Southwest)
                {
                    theDrawingAttributes.Color = System.Drawing.Color.Blue;
                }
                theInkOverlay.Selection.ModifyDrawingAttributes(theDrawingAttributes);
                this.Refresh();
            }
        }

        private void theCheckBox_CheckedChanged(object sender, System.EventArgs e)
        {
            // Cannot change EditingMode while the InkOverlay is collecting ink
            if (true == theInkOverlay.CollectingInk)
            {
                theCheckBox.Checked = !theCheckBox.Checked;
                return;
            }

            // Toggle the EditingMode between Inking and Selection
            if (theInkOverlay.EditingMode == InkOverlayEditingMode.Ink)
            {
                theInkOverlay.EditingMode = InkOverlayEditingMode.Select;
            }
            else
            {
                theInkOverlay.EditingMode = InkOverlayEditingMode.Ink;
            }
        }
    }
}                

[VB.NET]

This Microsoft® Visual Basic® .NET example uses a check box, theCheckBox, to toggle an InkOverlay object, theInkOverlay, between inking and selection modes, and uses the results from the HitTestSelection method to change the color of the selection when a user clicks one of the sizing handles of the selection rectangle.


Option Explicit On

Imports System
Imports System.Windows.Forms
Imports Microsoft.Ink

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private WithEvents theInkOverlay As Microsoft.Ink.InkOverlay
    Private WithEvents theCheckBox As System.Windows.Forms.CheckBox

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub InitializeComponent()
        Me.theCheckBox = New System.Windows.Forms.CheckBox()
        Me.SuspendLayout()
        '
        'theCheckBox
        '
        Me.theCheckBox.Name = "theCheckBox"
        Me.theCheckBox.TabIndex = 0
        Me.theCheckBox.Text = "Selection Mode"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.theCheckBox})
        Me.Name = "Form1"
        Me.Text = "HitTestSelection"
        Me.ResumeLayout(False)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
        ' Create the InkOverlay
        theInkOverlay = New InkOverlay(Handle)
        ' Using an Attach Mode of behind lets you check the check box instead of inking on it.
        theInkOverlay.AttachMode = InkOverlayAttachMode.Behind
        ' Enable the InkOverlay
        theInkOverlay.Enabled = True
    End Sub

    Private Sub theInkOverlay_MouseDown(ByVal sender As Object, ByVal e As Microsoft.Ink.CancelMouseEventArgs)_
        Handles theInkOverlay.MouseDown
        If theInkOverlay.EditingMode = InkOverlayEditingMode.Select Then
            Dim result As SelectionHitResult
            result = theInkOverlay.HitTestSelection(e.X, e.Y)
            Dim theDrawingAttributes As New DrawingAttributes()
            If result = SelectionHitResult.Northwest Then
                theDrawingAttributes.Color = Color.Green
            ElseIf result = SelectionHitResult.Northeast Then
                theDrawingAttributes.Color = Color.Red
            ElseIf result = SelectionHitResult.Southeast Then
                theDrawingAttributes.Color = Color.Yellow
            ElseIf result = SelectionHitResult.Southwest Then
                theDrawingAttributes.Color = Color.Blue
            End If
            theInkOverlay.Selection.ModifyDrawingAttributes(theDrawingAttributes)
            Refresh()
        End If
    End Sub

    Private Sub theCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles theCheckBox.CheckedChanged
        ' Cannot change EditingMode while the InkOverlay is collecting ink
        If theInkOverlay.CollectingInk Then
            theCheckBox.Checked = Not theCheckBox.Checked
        End If

        'Toggle the EditingMode between Inking and Selection
        If theInkOverlay.EditingMode = InkOverlayEditingMode.Ink Then
            theInkOverlay.EditingMode = InkOverlayEditingMode.Select
        Else
            theInkOverlay.EditingMode = InkOverlayEditingMode.Ink
        End If
    End Sub

End Class
                

See Also

Show: