聚热点 juredian

鼠标手写输入法 电脑上怎么手写输入

在如今这个时代,对这个功能的需求量可能已经很少了,但是这也不妨碍我们或多或少的会碰到一些稀奇古怪的需求,多接触一些总归是没错的。

本篇主要是用到了Microsoft.Ink来实现一个手写输入,也就是类似于手机输入法中的手写功能。

实现功能:

用鼠标或者手指在屏幕上写字并识别输入到文本框

开发环境:

开发工具: Visual Studio 2013

.NET Framework版本:4.5

实现代码:

InkCollector ink;

RecognizerContext recogn;publicinputFrm(){

InitializeComponent();

Control.ControlCollection btnList = panel3.Controls;foreach(Control cinbtnList)

{

(casButton).Click += (s, e) =>

{if(textBox1.Text.Length >0)

{intintStart = textBox1.SelectionStart;

textBox1.Text = textBox1.Text.Remove(intStart -1,1);

textBox1.Text = textBox1.Text.Insert(intStart -1, (sasButton).Text);

textBox1.SelectionStart = intStart;

}

};

}

}privatevoidinputFrm_Load(objectsender, EventArgs e){//创建笔画采集器ink =newInkCollector(picText.Handle);

ink.Enabled =true;

ink.Stroke +=newInkCollectorStrokeEventHandler((s, e1) =>

{

recogn.StopBackgroundRecognition();

recogn.Strokes.Add(e1.Stroke);

recogn.BackgroundRecognizeWithAlternates(0);

});//创建识别器Recognizers recs =newRecognizers();

Recognizer rec = recs.GetDefaultRecognizer();

recogn = rec.CreateRecognizerContext();

recogn.RecognitionFlags = RecognitionModes.WordMode;

recogn.Strokes = ink.Ink.Strokes;

recogn.RecognitionWithAlternates +=newRecognizerContextRecognitionWithAlternatesEventHandler((s, e1) =>

{stringresult ="";

RecognitionAlternates alts;if(e1.RecognitionStatus == RecognitionStatus.NoError)

{

alts = e1.Result.GetAlternatesFromSelection();foreach(RecognitionAlternate altinalts)

{

result += alt.ToString() +" ";

}

}

result = result.Trim();

Control.CheckForIllegalCrossThreadCalls =false;string[] arr = result.Split();for(inti =0; i < arr.Length; i++)

{stringstr ="btnSelect_"+ (i +1);

Control btn = panel3.Controls.Find(str,false).First();

btn.Text = arr[i];

}

Control.CheckForIllegalCrossThreadCalls =true;

});

}privatevoidpicText_MouseUp(objectsender, MouseEventArgs e){

timer1.Enabled =true;

}privatevoidpicText_MouseDown(objectsender, MouseEventArgs e){

timer1.Enabled =false;

}privatevoidtimer1_Tick(objectsender, EventArgs e){

Write();if(!ink.CollectingInk)

{

Strokes strokesToDelete = ink.Ink.Strokes;

recogn.StopBackgroundRecognition();

ink.Ink.DeleteStrokes(strokesToDelete);

recogn.Strokes = ink.Ink.Strokes;

ink.Ink.DeleteStrokes();

picText.Refresh();

}

timer1.Stop();

}privatevoidWrite(){

List lstPoints =newList();foreach(varstrokeinink.Ink.Strokes)

{

lstPoints.AddRange(stroke.GetPoints());

}

ink.Ink.DeleteStrokes();

Stroke sk = ink.Ink.CreateStroke(lstPoints.ToArray());

recogn.Strokes.Add(sk);

textBox1.SelectedText = ink.Ink.Strokes.ToString();

}privatevoidbtnDel_Click(objectsender, EventArgs e){if(!string.IsNullOrEmpty(textBox1.Text))

textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length -1);

}privatevoidbtnClear_Click(objectsender, EventArgs e){if(!ink.CollectingInk)

{

Strokes strokesToDelete = ink.Ink.Strokes;

recogn.StopBackgroundRecognition();

ink.Ink.DeleteStrokes(strokesToDelete);

recogn.Strokes = ink.Ink.Strokes;

ink.Ink.DeleteStrokes();

picText.Refresh();

textBox1.Clear();

}

}

实现效果:

最后附上一个关于Microsoft.Ink的API说明文档:https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-3.5/ms581553(v=vs.90),以方便大家更加详细的了解以及使用。

有需要源代码的朋友们可私信:手写输入获取

由简入繁,拿来即用

后续精彩,持续关注

搜索建议:
热博

 雅俗皆乐幸福中国作文

雅俗皆乐幸福中国作文在日复一日的学习、工作或生活中,大家都有写作文的经历,对作文很是熟悉吧,作文是经过人的思想考虑和语言组织,通过文字来表达一个主题意义的记叙方...(展开)

热博

 【歌词】琰洋城堡 / 歌手:冬眠

琰洋城堡演唱:冬眠、心酸老八词:李初寒、冬眠曲:橙子辰、冬眠编曲:橙子辰混音:季薇儿海报:琰洋出品:琰琰初橙音乐工作室发行:音唯唱片恋爱就是与你一起相伴到老做浪...(展开)

热博

 【歌词】God Speed Yo...

GodSpeedYouBabyafloodofcircle作詞:佐々木亮介作曲:佐々木亮介毎日どこかで事故ってる 今日も鉄の塊でハイウェイの上 自分の番は来ない...(展开)