Compartir a través de


InkOverlay.HitTestSelection Method

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

Namespace: Microsoft.Ink
Assembly: Microsoft.Ink (in microsoft.ink.dll)

Syntax

'Declaration
Public Function HitTestSelection ( _
    X As Integer, _
    Y As Integer _
) As SelectionHitResult
'Usage
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
Not applicable.

Parameters

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

Return Value

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

Remarks

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

Note

When running an ink app on a Windows XP desktop machine that is set to 120dpi, the HitTestSelection method is off by a scaling factor when the point supplied is converted from ink space to pixel space.

Example

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;
            }
        }
    }
}

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

Platforms

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

InkOverlay Class
InkOverlay Members
Microsoft.Ink Namespace
SelectionHitResult