CPDFSearchInputUI.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Input;
  6. namespace ComPDFKit.Controls.PDFControlUI
  7. {
  8. public partial class CPDFSearchInputUI : UserControl
  9. {
  10. public enum MoveDirection
  11. {
  12. Previous = 0,
  13. Next = 1
  14. };
  15. public event EventHandler<string> SearchEvent;
  16. public event EventHandler ClearEvent;
  17. public event EventHandler<MoveDirection> MoveResultEvent;
  18. public string SearchKeyWord
  19. {
  20. get
  21. {
  22. return SearchTextBox.Text;
  23. }
  24. set
  25. {
  26. SearchTextBox.Text = value;
  27. }
  28. }
  29. public string ReplaceWord
  30. {
  31. get
  32. {
  33. return ReplaceTextBox.Text;
  34. }
  35. set
  36. {
  37. ReplaceTextBox.Text = value;
  38. }
  39. }
  40. public double InputTextBoxWidth
  41. {
  42. get
  43. {
  44. return SearchTextBox.Width;
  45. }
  46. set
  47. {
  48. SearchTextBox.Width = value;
  49. ReplaceTextBox.Width = value;
  50. }
  51. }
  52. public double InputTextBoxHeight
  53. {
  54. get
  55. {
  56. return SearchTextBox.Height;
  57. }
  58. set
  59. {
  60. SearchTextBox.Height = value;
  61. ReplaceTextBox.Height = value;
  62. }
  63. }
  64. public CPDFSearchInputUI()
  65. {
  66. InitializeComponent();
  67. }
  68. private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
  69. {
  70. if (e.Key == Key.Enter && string.IsNullOrEmpty(SearchKeyWord)==false)
  71. {
  72. SearchEvent?.Invoke(this, SearchKeyWord);
  73. }
  74. }
  75. private void TextClear_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  76. {
  77. SearchKeyWord = string.Empty;
  78. ClearEvent?.Invoke(this,new EventArgs());
  79. }
  80. private void SearchBtn_Click(object sender, RoutedEventArgs e)
  81. {
  82. if (string.IsNullOrEmpty(SearchKeyWord) == false)
  83. {
  84. Regex regex = new Regex(@"\s+");
  85. string result = regex.Replace(SearchKeyWord, " ");
  86. SearchEvent?.Invoke(this, result);
  87. }
  88. }
  89. private void ReplaceTextClear_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  90. {
  91. ReplaceTextBox.Text = string.Empty;
  92. }
  93. private void Previous_Click(object sender, RoutedEventArgs e)
  94. {
  95. MoveResultEvent?.Invoke(this,MoveDirection.Previous);
  96. }
  97. private void Next_Click(object sender, RoutedEventArgs e)
  98. {
  99. MoveResultEvent?.Invoke(this,MoveDirection.Next);
  100. }
  101. private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
  102. {
  103. if (string.IsNullOrEmpty(SearchKeyWord))
  104. {
  105. ClearEvent?.Invoke(this, new EventArgs());
  106. }
  107. }
  108. }
  109. }