基本信息
源码名称:c#实现手写,生成dll调用(含源码)
源码大小:2.05M
文件格式:.rar
开发语言:C#
更新时间:2021-12-23
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 3 元 
   源码介绍
c#实现手写,生成dll调用(含源码)

   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());
            }
        }
    }