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

懵懂先生 投稿文章鼠标手写输入法 电脑上怎么手写输入已关闭评论187阅读模式

文章源自略懂百科-http://wswcn.cn/54620.html

在如今这个时代,对这个功能的需求量可能已经很少了,但是这也不妨碍我们或多或少的会碰到一些稀奇古怪的需求,多接触一些总归是没错的。文章源自略懂百科-http://wswcn.cn/54620.html

本篇主要是用到了Microsoft.Ink来实现一个手写输入,也就是类似于手机输入法中的手写功能。文章源自略懂百科-http://wswcn.cn/54620.html

实现功能:文章源自略懂百科-http://wswcn.cn/54620.html

用鼠标或者手指在屏幕上写字并识别输入到文本框文章源自略懂百科-http://wswcn.cn/54620.html

开发环境:文章源自略懂百科-http://wswcn.cn/54620.html

开发工具: Visual Studio 2013文章源自略懂百科-http://wswcn.cn/54620.html

.NET Framework版本:4.5文章源自略懂百科-http://wswcn.cn/54620.html

实现代码:文章源自略懂百科-http://wswcn.cn/54620.html

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];
}文章源自略懂百科-http://wswcn.cn/54620.html

Control.CheckForIllegalCrossThreadCalls =true;文章源自略懂百科-http://wswcn.cn/54620.html

});文章源自略懂百科-http://wswcn.cn/54620.html

}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();
}
}文章源自略懂百科-http://wswcn.cn/54620.html

实现效果:文章源自略懂百科-http://wswcn.cn/54620.html

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

有需要源代码的朋友们可私信:手写输入获取文章源自略懂百科-http://wswcn.cn/54620.html

由简入繁,拿来即用文章源自略懂百科-http://wswcn.cn/54620.html

后续精彩,持续关注文章源自略懂百科-http://wswcn.cn/54620.html

文章源自略懂百科-http://wswcn.cn/54620.html

懵懂先生
  • 本文由 发表于 2022年10月20日 12:42:28
  • 转载请注明:http://wswcn.cn/54620.html
投稿文章

u启动pe装机工具失败怎么办_u启动重装系统步骤win10

有网友制作了win10 u盘启动盘,打算给win10系统重装修复一些系统故障问题,但是发现win10系统重装u盘启动不了怎么回事。下面就给大家分析下win10 u盘启动不了的原因和解决方法。 更多wi...
投稿文章

动图如何保存呢(动图怎么保存)

GIF的全称为Graphics Interchange Format,可译为图像互换格式,我们一般也称它为动图,它是一种位图图形文件格式,以8位色(即256种颜色)重现真彩色的图像。 GIF一般多用来...
投稿文章

妹汁是什么(妹汁是哪里来的)

岛国拟人化是越来越羞耻了,在C90里惊现一本自动贩售机的本子叫《朋友自贩机》,讲述了男主角与自动贩售机娘成了朋友,每天都为能喝上新鲜热辣的黄色热茶而感到治愈。 被炮姐残忍对待的自动贩售机,可能有一天会...
投稿文章

霸气英文网名大全

尊严这种东西,你得有实力捍卫,否则,那就是死要面子活受罪。今天可爱点小编带来一组英文昵称简短好听霸气分享给大家。Hanabi(映画)Weirdo.(怪人)Unicorn(独角兽)Soft sister...