Freigeben über


InkPicture.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 InkPicture
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 InkPicture.EditingMode property is set to the value of enumeration SelectionHitResult, Select.

Example

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.

[C#]

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

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.

[Visual Basic]

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

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

InkPicture Class
InkPicture Members
Microsoft.Ink Namespace
SelectionHitResult