实例介绍
【实例截图】
【核心代码】
public partial class InputMsgUc : UserControl
{
public string[] HandWriteRecognize { get; set; }
private static Brush _PreviousTextBoxBackgroundBrush = null;
private static Brush _PreviousTextBoxBorderBrush = null;
private static Thickness _PreviousTextBoxBorderThickness;
public static TextBox _CurrentControl;
static bool isNum = false;
//static bool IsStart = true;
//static SoundAbout Voicefunction;
public InputMsgUc()
{
InitializeComponent();
this.DataContext = _core;
}
public static bool GetInputMsgUc(DependencyObject obj)
{
return (bool)obj.GetValue(TextBoxChoiceProperty);
}
public static void SetInputMsgUc(DependencyObject obj, bool value)
{
obj.SetValue(TextBoxChoiceProperty, value);
}
public static readonly DependencyProperty TextBoxChoiceProperty =
DependencyProperty.RegisterAttached("InputMsgUc", typeof(bool), typeof(InputMsgUc), new UIPropertyMetadata(default(bool), TextBoxChoicePropertyChanged));
private static void TextBoxChoicePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
if (bool.Parse(e.NewValue.ToString()))
{
FrameworkElement host = sender as FrameworkElement;
if (host != null)
{
//host.GotFocus = new RoutedEventHandler(OnGotFocus);
host.LostFocus = new RoutedEventHandler(OnLostFocus);
host.PreviewMouseLeftButtonUp = Host_PreviewMouseLeftButtonUp;
}
}
else
{
FrameworkElement host = sender as FrameworkElement;
if (host != null)
{
//host.GotFocus -= new RoutedEventHandler(OnGotFocus);
host.LostFocus -= new RoutedEventHandler(OnLostFocus);
host.PreviewMouseLeftButtonUp -= Host_PreviewMouseLeftButtonUp;
}
}
}
static void OnLostFocus(object sender, RoutedEventArgs e)
{
TextBox host = sender as TextBox;
host.Background = _PreviousTextBoxBackgroundBrush;
host.BorderBrush = _PreviousTextBoxBorderBrush;
//if (Voicefunction != null)
//{
// //Voicefunction.StopIatDXVoiceToTxtOnLine();
// Voicefunction.VoiceFileToTxtDataReceive -= Voicefunction_VoiceFileToTxtDataReceive;//获得识别结果事件
//}
}
private static void Host_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
TextBox host = sender as TextBox;
_PreviousTextBoxBackgroundBrush = host.Background;
_PreviousTextBoxBorderBrush = host.BorderBrush;
_PreviousTextBoxBorderThickness = host.BorderThickness;
host.Background = Brushes.Transparent;
//host.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF125c87"));
host.BorderBrush = Brushes.Red;
//host.BorderThickness = new Thickness(1);
//host.CaretBrush = Brushes.Blue;
_CurrentControl = host;
//string str = host.Tag.ToString();
//if (str.Contains("号码") || str.Contains("手机"))
//{
// InputModel = 3;
//}
//else
//{
// InputModel = 0;
//}
}
private void SelectCharactorButtonOnClick(object sender, RoutedEventArgs e)
{
try
{
var button = sender as Button;
string text = string.Empty;
if (string.IsNullOrEmpty(button.Uid))
{
text = button.Content.ToString();
}
else
{
text = button.Uid;
}
int start = _CurrentControl.SelectionStart;
_CurrentControl.Text = _CurrentControl.Text.Insert(start, text);
_CurrentControl.SelectionStart = start text.Length;
_CurrentControl.Focus();
if (!isNum)
{
Clear();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
private void WritingCanvasOnStrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
{
string[] str = _core.Recognize(this.WritingCanvas.Strokes);
HandWriteRecognize = str;
Clear();
//_CurrentControl.Focus();
}
private readonly RecognizationCore _core = new RecognizationCore();
private void Clear()
{
this.WritingCanvas.Strokes.Clear();
_core.ClearAlternates();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Ink.DrawingAttributes inkDA = new System.Windows.Ink.DrawingAttributes();
inkDA.Width = 5;
inkDA.Height = 5;
WritingCanvas.DefaultDrawingAttributes.Color = Colors.Transparent;//手写笔迹透明
//this.WritingCanvas.DefaultDrawingAttributes = inkDA;
LoadModel();
}
private void LoadModel()
{
try
{
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
}
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论