CPDFSearchInputUI.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. namespace Compdfkit_Tools.PDFControlUI
  6. {
  7. public partial class CPDFSearchInputUI : UserControl
  8. {
  9. public event EventHandler<string> SearchEvent;
  10. public event EventHandler ClearEvent;
  11. public string SearchKeyWord
  12. {
  13. get
  14. {
  15. return SearchTextBox.Text;
  16. }
  17. set
  18. {
  19. SearchTextBox.Text = value;
  20. }
  21. }
  22. public double InputTextBoxWidth
  23. {
  24. get
  25. {
  26. return SearchTextBox.Width;
  27. }
  28. set
  29. {
  30. SearchTextBox.Width = value;
  31. }
  32. }
  33. public double InputTextBoxHeight
  34. {
  35. get
  36. {
  37. return SearchTextBox.Height;
  38. }
  39. set
  40. {
  41. SearchTextBox.Height = value;
  42. }
  43. }
  44. public CPDFSearchInputUI()
  45. {
  46. InitializeComponent();
  47. }
  48. private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
  49. {
  50. if (e.Key == Key.Enter && string.IsNullOrEmpty(SearchKeyWord)==false)
  51. {
  52. SearchEvent?.Invoke(this, SearchKeyWord);
  53. }
  54. }
  55. private void TextClear_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  56. {
  57. SearchKeyWord = string.Empty;
  58. ClearEvent?.Invoke(this,new EventArgs());
  59. }
  60. private void SearchBtn_Click(object sender, RoutedEventArgs e)
  61. {
  62. if (string.IsNullOrEmpty(SearchKeyWord) == false)
  63. {
  64. SearchEvent?.Invoke(this, SearchKeyWord);
  65. }
  66. }
  67. private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
  68. {
  69. if (string.IsNullOrEmpty(SearchKeyWord))
  70. {
  71. ClearEvent?.Invoke(this, new EventArgs());
  72. }
  73. }
  74. }
  75. }