using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Prism.Ioc; using Prism.Regions; namespace PDF_Master.Views.Dialog.ServiceDialog { /// /// CodeRegion.xaml 的交互逻辑 /// public partial class CodeRegion : UserControl { public CodeRegion() { InitializeComponent(); Loaded += Focus_Loaded; } private void Focus_Loaded(object sender, RoutedEventArgs e) { text_Code1.Focus(); } private void Code_TextChanged(object sender, TextChangedEventArgs e) { Grid_RegisterVis.Visibility = Visibility.Collapsed; text_Code1.Select(text_Code1.Text.Length, 0); if (text_Code1.Text.Length == 1) { text_Code2.Focus(); } else if (text_Code1.Text.Length > 1) { string str = text_Code1.Text; text_Code1.Text = str.Substring(0, 1); str = str.Remove(0, 1); if (str.Length > 0) { text_Code2.Text = str; } } } private void text_Code2_TextChanged(object sender, TextChangedEventArgs e) { Grid_RegisterVis.Visibility = Visibility.Collapsed; text_Code2.Select(text_Code2.Text.Length, 0); if (text_Code2.Text.Length == 1) { text_Code3.Focus(); } else if (text_Code2.Text.Length > 1) { string str = text_Code2.Text; text_Code2.Text = str.Substring(0, 1); str = str.Remove(0, 1); if (str.Length > 0) { text_Code3.Text = str; } } } private void text_Code3_TextChanged(object sender, TextChangedEventArgs e) { Grid_RegisterVis.Visibility = Visibility.Collapsed; text_Code3.Select(text_Code3.Text.Length, 0); if (text_Code3.Text.Length == 1) { text_Code4.Focus(); } else if (text_Code3.Text.Length > 1) { string str = text_Code3.Text; text_Code3.Text = str.Substring(0, 1); str = str.Remove(0, 1); if (str.Length > 0) { text_Code4.Text = str; } } } private void text_Code4_TextChanged(object sender, TextChangedEventArgs e) { Grid_RegisterVis.Visibility = Visibility.Collapsed; text_Code4.Select(text_Code4.Text.Length, 0); if (this.text_Code4.Text.Length == 1) { this.text_Code5.Focus(); } else if (text_Code4.Text.Length > 1) { string str = text_Code4.Text; text_Code4.Text = str.Substring(0, 1); str = str.Remove(0, 1); if (str.Length > 0) { text_Code5.Text = str; } } } private void text_Code5_TextChanged(object sender, TextChangedEventArgs e) { Grid_RegisterVis.Visibility = Visibility.Collapsed; text_Code5.Select(text_Code5.Text.Length, 0); if (this.text_Code5.Text.Length == 1) { this.text_Code6.Focus(); } else if (text_Code5.Text.Length > 1) { string str = text_Code5.Text; text_Code5.Text = str.Substring(0, 1); str = str.Remove(0, 1); if (str.Length > 0) { text_Code6.Text = str; } } } private void text_Code6_TextChanged(object sender, TextChangedEventArgs e) { Grid_RegisterVis.Visibility = Visibility.Collapsed; text_Code6.Select(text_Code6.Text.Length, 0); if (this.text_Code6.Text.Length == 1) { text_Code6.Focus(); } else if (text_Code6.Text.Length > 1) { string str = text_Code6.Text; text_Code6.Focus(); text_Code6.Text = str.Substring(0, 1); } } private void text_Code1_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Back) { text_Code1.Text = ""; text_Code1.Focus(); } } private void text_Code2_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Back) { text_Code2.Text = ""; text_Code1.Focus(); text_Code1.Select(text_Code1.Text.Length, 0); } } private void text_Code3_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Back) { text_Code3.Text = ""; text_Code2.Focus(); text_Code2.Select(text_Code2.Text.Length, 0); } } private void text_Code4_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Back) { text_Code4.Text = ""; text_Code3.Focus(); text_Code3.Select(text_Code3.Text.Length, 0); } } private void text_Code5_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Back) { text_Code5.Text = ""; text_Code4.Focus(); text_Code4.Select(text_Code4.Text.Length, 0); } } private void text_Code6_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Back) { text_Code6.Text = ""; text_Code5.Focus(); text_Code5.Select(text_Code5.Text.Length, 0); } } private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = new Regex("[^0-9]+").IsMatch(e.Text); } } }