Share via


InkOverlay.Selection Property

InkOverlay.Selection Property

Gets or sets the Strokes collection that is currently selected inside the InkOverlay control.

Definition

Visual Basic .NET Public Property Selection As Strokes
C# public Strokes Selection { get; set; }
Managed C++ public: __property Strokes* get_Selection();
public: __property void set_Selection(Strokes*);

Property Value

Microsoft.Ink.Strokes. The Strokes collection that is currently selected inside the InkOverlay control. The default value is an empty Strokes collection.

This property is read/write. This property has no default value.

Exceptions

COMException Leave Site:
ObjectDisposedException Leave Site:

Remarks

To get the bounding rectangle of the Strokes collection after it has been moved or resized, call the GetBoundingBox method of the Strokes collection returned by this property.

To get the bounding rectangle of of the Strokes collection before it was moved, handle the SelectionMoved event and get the OldSelectionBoundingRect property of the InkOverlaySelectionMovedEventArgs object.

To get the bounding rectangle of of the Strokes collection before it was resized, handle the SelectionResized event and get the OldSelectionBoundingRect property of the InkOverlaySelectionResizedEventArgs object.

Examples

[C#]

This C# example demonstrates use of the Selection property and using the HitTestSelection method. This application uses a check box, theCheckBox, to toggle an InkOverlay object, theInkOverlay, between inking and selection modes. The example also uses the HitTestSelection results to change the color of the selected strokes from the Selection property when one of the selection sizing handles of the selection rectangle is clicked.

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 overlay, add the mouse down event handler, and enable the overlay
        private void Form1_Load(object sender, System.EventArgs e)
        {
            theInkOverlay.MouseDown += new InkCollectorMouseDownEventHandler(theInkOverlay_MouseDown);
        }

        // Handle the mouse down event for the overlay
        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)
        {
            // Can't change EditingMode while the overlay 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 demonstrates use of the Selection property and using the HitTestSelection method. This application uses a check box, theCheckBox, to toggle an InkOverlay object, theInkOverlay, between inking and selection modes. The example also uses the HitTestSelection results to change the color of the selected strokes from the Selection property when one of the selection sizing handles of the selection rectangle is clicked.

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
        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
        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
        ' Can't change EditingMode while the overlay 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