Share via


InkPicture.HitTestSelection Method

InkPicture.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.

None0 Specifies no part of the selection was hit.
Northwest1 Specifies the northwest corner sizing handle was hit.
Southeast2 Specifies the southeast corner sizing handle was hit.
Northeast3 Specifies the northeast corner sizing handle was hit.
Southwest4 Specifies the southwest corner sizing handle was hit.
East5 Specifies the east side sizing handle was hit.
West6 Specifies the west side sizing handle was hit.
North7 Specifies the north side sizing handle was hit.
South8 Specifies the south side sizing handle was hit.
Selection9 Specifies the selection itself was hit (no selection handle was hit).

Exceptions

ObjectDisposedException Leave Site: The InkPicture control is disposed.

Remarks

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

Examples

[C#]

This C# example uses a check box, theCheckBox, to toggle an InkPicture control, theInkPicture, 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 System.Windows.Forms.CheckBox theCheckBox;
        private Microsoft.Ink.InkPicture theInkPicture;

        public Form1()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.theCheckBox = new System.Windows.Forms.CheckBox();
            this.theInkPicture = new Microsoft.Ink.InkPicture();
            this.SuspendLayout();
            //
            // theCheckBox
            //
            this.theCheckBox.Name = "theCheckBox";
            this.theCheckBox.TabIndex = 0;
            this.theCheckBox.Text = "Selection Mode";
            this.theCheckBox.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
            //
            // theInkPicture
            //
            this.theInkPicture.Location = new System.Drawing.Point(24, 40);
            this.theInkPicture.MarginX = -2147483648;
            this.theInkPicture.MarginY = -2147483648;
            this.theInkPicture.Name = "theInkPicture";
            this.theInkPicture.Size = new System.Drawing.Size(248, 200);
            this.theInkPicture.TabIndex = 1;
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.theInkPicture,
                                                                          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 theInkPicture, add the mouse down event handler, and enable theInkPicture
        private void Form1_Load(object sender, System.EventArgs e)
        {
            theInkPicture.MouseDown += new MouseEventHandler(theInkPicture_MouseDown);
            theInkPicture.InkEnabled = true;
        }

        // Handle the mouse down event for the InkPicture
        private void theInkPicture_MouseDown(object sender, MouseEventArgs e)
        {
            if (theInkPicture.EditingMode == InkOverlayEditingMode.Select)
            {
                SelectionHitResult result = theInkPicture.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;
                }
                theInkPicture.Selection.ModifyDrawingAttributes(theDrawingAttributes);
                this.Refresh();
            }
        }

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

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

[VB.NET]

This Microsoft® Visual Basic® .NET example uses a check box, theCheckBox, to toggle an InkPicture control, theInkPicture, 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 theCheckBox As System.Windows.Forms.CheckBox

    Public Sub New()
        InitializeComponent()
    End Sub
    Friend WithEvents theInkPicture As Microsoft.Ink.InkPicture

    Private Sub InitializeComponent()
        Me.theCheckBox = New System.Windows.Forms.CheckBox()
        Me.theInkPicture = New Microsoft.Ink.InkPicture()
        Me.SuspendLayout()
        '
        'theCheckBox
        '
        Me.theCheckBox.Name = "theCheckBox"
        Me.theCheckBox.TabIndex = 0
        Me.theCheckBox.Text = "Selection Mode"
        '
        'theInkPicture
        '
        Me.theInkPicture.BackColor = System.Drawing.SystemColors.ControlLightLight
        Me.theInkPicture.Location = New System.Drawing.Point(16, 32)
        Me.theInkPicture.MarginX = -2147483648
        Me.theInkPicture.MarginY = -2147483648
        Me.theInkPicture.Name = "theInkPicture"
        Me.theInkPicture.Size = New System.Drawing.Size(264, 224)
        Me.theInkPicture.TabIndex = 1
        '
        '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.theInkPicture, 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
        theInkPicture.InkEnabled = True
    End Sub

    Private Sub theInkPicture_MouseDown(ByVal sender As System.Object, ByVal e As MouseEventArgs) _
    Handles theInkPicture.MouseDown
        If theInkPicture.EditingMode = InkOverlayEditingMode.Select Then
            Dim result As SelectionHitResult
            result = theInkPicture.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
            theInkPicture.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
        ' Can't change EditingMode while the InkPicture is collecting ink
        If theInkPicture.CollectingInk Then
            theCheckBox.Checked = Not theCheckBox.Checked
        End If

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

See Also