using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using Microsoft.Ink;
using System.Runtime.InteropServices;
using System.Text;
namespace inkControl
{
///
/// Summary description for UserControl1.
///
//==============================================================
//InkEdit - to expose an event to IE
//==============================================================
//public delegate void InkEditRecognitionEventHandler();
[GuidAttribute("1F98211C-7A71-4588-8D4A-AD85CA80BAE7"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface ControlEvents
{
// Add DisIdAttribute to any members in the source interface to specify the COM DISPID.
[DispIdAttribute(1)]
void InkEditRecognition(object sender, System.EventArgs e);
}
// Add a ComSourceInterfaces attribute to the control to identify the list
// of interfaces that are exposed as COM event sources.
[ComSourceInterfaces("inkControl.ControlEvents")]
public class MyInkControl : System.Windows.Forms.UserControl
{
private Microsoft.Ink.InkEdit inkEdit1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private Microsoft.Ink.InkPicture inkPicture1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public MyInkControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.inkEdit1 = new Microsoft.Ink.InkEdit();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.inkPicture1 = new Microsoft.Ink.InkPicture();
this.SuspendLayout();
//
// inkEdit1
//
this.inkEdit1.BackColor = System.Drawing.SystemColors.Window;
this.inkEdit1.Cursor = System.Windows.Forms.Cursors.IBeam;
this.inkEdit1.Location = new System.Drawing.Point(32, 40);
this.inkEdit1.Name = "inkEdit1";
this.inkEdit1.Size = new System.Drawing.Size(240, 72);
this.inkEdit1.TabIndex = 0;
this.inkEdit1.Text = "";
this.inkEdit1.UseMouseForInput = true;
this.inkEdit1.Recognition += new Microsoft.Ink.InkEditRecognitionEventHandler(this.inkEdit1_Recognition);
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(240, 23);
this.label1.TabIndex = 1;
this.label1.Text = "InkEdit - UseMouseForInput";
//
// label2
//
this.label2.Location = new System.Drawing.Point(296, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(240, 23);
this.label2.TabIndex = 2;
this.label2.Text = "InkPicture";
//
// inkPicture1
//
this.inkPicture1.BackColor = System.Drawing.Color.White;
this.inkPicture1.Location = new System.Drawing.Point(296, 40);
this.inkPicture1.MarginX = -2147483648;
this.inkPicture1.MarginY = -2147483648;
this.inkPicture1.Name = "inkPicture1";
this.inkPicture1.Size = new System.Drawing.Size(240, 72);
this.inkPicture1.TabIndex = 3;
//
// MyInkControl
//
this.BackColor = System.Drawing.Color.Silver;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.inkPicture1,
this.label2,
this.label1,
this.inkEdit1});
this.Name = "MyInkControl";
this.Size = new System.Drawing.Size(550, 125);
this.Load += new System.EventHandler(this.UserControl1_Load);
this.ResumeLayout(false);
}
#endregion
private void UserControl1_Load(object sender, System.EventArgs e)
{
}
//==============================================================
//InkEdit
//==============================================================
private void inkEdit1_Recognition(object sender, Microsoft.Ink.InkEditRecognitionEventArgs e)
{
this.Reco = e.RecognitionResult.TopString;
if (InkEditRecognition != null)
InkEditRecognition(sender, e);
}
public event System.EventHandler InkEditRecognition;
private string color;
public string Color
{
get
{
return color;
}
set
{
color = value;
inkEdit1.DrawingAttributes.Color = System.Drawing.Color.FromName(value);
}
}
private string reco;
public string Reco
{
get
{
return reco;
}
set
{
reco = value;
}
}
//==============================================================
//InkPicture
//==============================================================
public void Clear()
{
inkPicture1.Ink.DeleteStrokes();
inkPicture1.Refresh();
}
private string base64;
public string Base64
{
get
{
base64 = this.GetBase64ISF();
return base64;
}
set
{
base64 = value;
}
}
private string GetBase64ISF()
{
UTF8Encoding utf8 = new UTF8Encoding();
byte[] base64ISF_bytes;
string base64ISF_string;
base64ISF_bytes = inkPicture1.Ink.Save(PersistenceFormat.Base64InkSerializedFormat);
base64ISF_string = utf8.GetString(base64ISF_bytes);
return base64ISF_string;
}
}
}