using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using Microsoft.Ink; using System.Runtime.InteropServices; namespace tabletSign { /// /// Summary description for Form1. /// public class FormSign : System.Windows.Forms.Form { private System.Windows.Forms.Button tabletBut; private Microsoft.Ink.InkEdit inkEdit1; private System.Windows.Forms.StatusBar statusBar1; private System.Windows.Forms.GroupBox icBox; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public FormSign() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.tabletBut = new System.Windows.Forms.Button(); this.inkEdit1 = new Microsoft.Ink.InkEdit(); this.statusBar1 = new System.Windows.Forms.StatusBar(); this.icBox = new System.Windows.Forms.GroupBox(); this.SuspendLayout(); // // tabletBut // this.tabletBut.Location = new System.Drawing.Point(8, 8); this.tabletBut.Name = "tabletBut"; this.tabletBut.TabIndex = 0; this.tabletBut.Text = "tablet"; this.tabletBut.Click += new System.EventHandler(this.tabletBut_Click); // // inkEdit1 // this.inkEdit1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); this.inkEdit1.HideSelection = false; this.inkEdit1.Location = new System.Drawing.Point(0, 40); this.inkEdit1.Name = "inkEdit1"; this.inkEdit1.Size = new System.Drawing.Size(360, 288); this.inkEdit1.TabIndex = 1; this.inkEdit1.Text = ""; this.inkEdit1.Stroke += new Microsoft.Ink.InkEditStrokeEventHandler(this.inkEdit1_Stroke); // // statusBar1 // this.statusBar1.Location = new System.Drawing.Point(0, 336); this.statusBar1.Name = "statusBar1"; this.statusBar1.Size = new System.Drawing.Size(704, 22); this.statusBar1.TabIndex = 2; // // icBox // this.icBox.BackColor = System.Drawing.Color.White; this.icBox.Location = new System.Drawing.Point(376, 40); this.icBox.Name = "icBox"; this.icBox.Size = new System.Drawing.Size(320, 288); this.icBox.TabIndex = 3; this.icBox.TabStop = false; this.icBox.Text = "inkCollector"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(704, 358); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.icBox, this.statusBar1, this.inkEdit1, this.tabletBut}); this.Name = "Form1"; this.Text = "tabletSign"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new FormSign()); } Tablets theTablets = null; Tablet penTablet = null; //InkCollector private InkCollector ic; [DllImport("user32.dll")] private static extern long GetSystemMetrics(long nIndex); private bool IsTabletPcEditionOs() { const long SM_TABLETPC = 86; long res = GetSystemMetrics(SM_TABLETPC); if(res == 0) return false; else return true; } //TODO this is not working for me? private bool AreTabletComponentsInstalled() { //object o = Activator.CreateInstanceFrom("Microsoft.Ink", "Microsoft.Ink.InkCollector"); //object o = Activator.CreateInstance("Microsoft.Ink", "Microsoft.Ink.InkCollector"); Type t = Type.GetType("Microsoft.Ink.InkCollector"); if(t == null) return false; object o = Activator.CreateInstance(t); if(o == null) return false; else return true; } private void Form1_Load(object sender, System.EventArgs e) { //am i on a Tablet PC with components installed? bool res = this.IsTabletPcEditionOs(); if(res == false) MessageBox.Show("Not Tablet PC Edition OS"); res = this.AreTabletComponentsInstalled(); if(res == false) MessageBox.Show("Tablet PC Components Not Installed"); theTablets = new Tablets(); //TODO figure out what it supports, if it is a pen foreach(Tablet t in theTablets) { if(t.IsPacketPropertySupported(PacketProperty.NormalPressure) == true) { penTablet = t; //grab 1st tablet that supports pressure continue; } } //InkCollector ic = new InkCollector(icBox.Handle); ic.CollectionMode = CollectionMode.InkOnly; Guid [] ga = new Guid[5]; ga[0] = PacketProperty.X; ga[1] = PacketProperty.Y; ga[2] = PacketProperty.NormalPressure; ga[3] = PacketProperty.XTiltOrientation; ga[4] = PacketProperty.YTiltOrientation; ic.DesiredPacketDescription = ga; ic.NewPackets += new InkCollectorNewPacketsEventHandler(NewPackets); ic.NewInAirPackets += new InkCollectorNewInAirPacketsEventHandler(NewInAirPackets); //invisible ink - blind sig //HACK - me //ic.DefaultDrawingAttributes.Color = Color.Transparent; //BETTER - Arin Goldberg //ic.DynamicRendering = false; //also cancel in the stroke event handler so it is not saved //ic.Stroke += new InkCollectorStrokeEventHandler(Stroke); ic.Enabled = true; } private void Stroke(object sender, Microsoft.Ink.InkCollectorStrokeEventArgs e) { e.Cancel = true; } int renderCount = 0; //default is x, y, and normalPressure private void NewPackets(object sender, InkCollectorNewPacketsEventArgs e) { if(renderCount >= 3) { renderCount = 0; int [] ia = e.PacketData; inkEdit1.AppendText("\r\n DOWN "); for(int i=0; i= 3) { renderCount = 0; int [] ia = e.PacketData; inkEdit1.AppendText("\r\n UP "); for(int i=0; i