InkOverlay.Selection Property
Gets or sets the Strokes collection that is currently selected inside the InkOverlay control.
Namespace: Microsoft.Ink
Assembly: Microsoft.Ink (in microsoft.ink.dll)
Syntax
'Declaration
Public Property Selection As Strokes
'Usage
Dim instance As InkOverlay
Dim value As Strokes
value = instance.Selection
instance.Selection = value
public Strokes Selection { get; set; }
public:
property Strokes^ Selection {
Strokes^ get ();
void set (Strokes^ value);
}
/** @property */
public Strokes get_Selection ()
/** @property */
public void set_Selection (Strokes value)
public function get Selection () : Strokes
public function set Selection (value : Strokes)
Not applicable.
Property Value
The Strokes collection that is currently selected inside the InkOverlay control. The default value is an empty Strokes collection.
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.
Example
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;
}
}
}
}
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
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
Strokes
Microsoft.Ink.Strokes.GetBoundingBox
InkOverlaySelectionMovedEventArgs.OldSelectionBoundingRect