using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Ink;
namespace CSInAirPacketEvents
{
public class Form1 : System.Windows.Forms.Form
{
//...
InkCollector theInkCollector;
int indexX, indexY;
Rectangle rectInterest;
bool thickBorder;
public Form1()
{
//...
//Initialize the InkCollector object.
theInkCollector= new InkCollector(Handle);
theInkCollector.Enabled = true;
//Initialize the target rectangle
rectInterest = new Rectangle(40, 40, 200, 80);
thickBorder = false;
//Save the X and Y data locations within the packet data.
GetXYIndexes(ref indexX, ref indexY);
//Add the event handler for in-air packets
theInkCollector.NewInAirPackets += new InkCollectorNewInAirPacketsEventHandler(NewInAirPackets_Event);
}
//...
private void GetXYIndexes(ref int theXIndex, ref int theYIndex)
{
// Get the indexes of the X and Y data within the raw
// packet data array.
Guid [] theGuids = theInkCollector.DesiredPacketDescription;
for (int i = 0; i < theGuids.Length; i++)
{
if (theGuids[i].Equals(PacketProperty.X))
theXIndex = i;
if (theGuids[i].Equals(PacketProperty.Y))
theYIndex = i;
}
}
private void NewInAirPackets_Event(object sender, InkCollectorNewInAirPacketsEventArgs e)
{
Graphics g = this.CreateGraphics();
Point [] pt = new Point [1];
pt[0].X = e.PacketData[indexX];
pt[0].Y = e.PacketData[indexY];
theInkCollector.Renderer.InkSpaceToPixel(g, ref pt);
// The event may return with data for multiple packets.
// To simplify things, we'll only look at the first.
if (rectInterest.Contains(pt[0].X, pt[0].Y))
{
if (!thickBorder)
{
thickBorder = true;
Refresh();
}
}
else
{
if (thickBorder)
{
thickBorder = false;
Refresh();
}
}
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen thePen = new Pen(Color.Black, 2);
if (thickBorder)
thePen.Width = 5;
g.DrawRectangle(thePen, rectInterest);
}
// Event handler for the form's closed event
private void Form1_Closed(object sender, System.EventArgs e)
{
theInkCollector.Dispose();
theInkCollector= null;
}
}
}