PreviewSearchForm.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4. using FastReport.Utils;
  5. using FastReport.Preview;
  6. namespace FastReport.Forms
  7. {
  8. internal partial class PreviewSearchForm : BaseDialogForm
  9. {
  10. private PreviewTab previewTab;
  11. private bool firstSearch;
  12. private static string[] FLastSearch;
  13. private static bool FMatchCase;
  14. private static bool FMatchWholeWord;
  15. public PreviewTab PreviewTab
  16. {
  17. get { return previewTab; }
  18. set { previewTab = value; }
  19. }
  20. private void cbxFind_TextChanged(object sender, EventArgs e)
  21. {
  22. firstSearch = true;
  23. }
  24. private void btnOk_Click(object sender, EventArgs e)
  25. {
  26. if (cbxFind.Text == "")
  27. return;
  28. btnOk.Enabled = false;
  29. btnCancel.Enabled = false;
  30. if (firstSearch)
  31. {
  32. if (!PreviewTab.Find(cbxFind.Text, cbMatchCase.Checked, cbMatchWholeWord.Checked))
  33. FRMessageBox.Information(Res.Get("Forms,SearchReplace,NotFound"));
  34. else
  35. firstSearch = false;
  36. }
  37. else
  38. {
  39. if (!PreviewTab.FindNext(cbxFind.Text, cbMatchCase.Checked, cbMatchWholeWord.Checked))
  40. {
  41. FRMessageBox.Information(Res.Get("Forms,SearchReplace,NoMoreFound"));
  42. firstSearch = true;
  43. }
  44. }
  45. btnOk.Enabled = true;
  46. btnCancel.Enabled = true;
  47. }
  48. private void btnCancel_Click(object sender, EventArgs e)
  49. {
  50. Close();
  51. }
  52. private void PreviewSearchForm_FormClosed(object sender, FormClosedEventArgs e)
  53. {
  54. Done();
  55. }
  56. private void Init()
  57. {
  58. if (FLastSearch != null)
  59. {
  60. foreach (string s in FLastSearch)
  61. {
  62. cbxFind.Items.Add(s);
  63. }
  64. }
  65. cbMatchCase.Checked = FMatchCase;
  66. cbMatchWholeWord.Checked = FMatchWholeWord;
  67. firstSearch = true;
  68. }
  69. private void Done()
  70. {
  71. List<string> items = new List<string>();
  72. foreach (object item in cbxFind.Items)
  73. {
  74. items.Add(item.ToString());
  75. }
  76. if (items.IndexOf(cbxFind.Text) == -1)
  77. items.Add(cbxFind.Text);
  78. FLastSearch = items.ToArray();
  79. FMatchCase = cbMatchCase.Checked;
  80. FMatchWholeWord = cbMatchWholeWord.Checked;
  81. }
  82. public override void Localize()
  83. {
  84. base.Localize();
  85. MyRes res = new MyRes("Forms,SearchReplace");
  86. Text = Res.Get("Forms,PreviewSearch");
  87. lblFind.Text = res.Get("Find");
  88. gbOptions.Text = res.Get("Options");
  89. cbMatchCase.Text = res.Get("MatchCase");
  90. cbMatchWholeWord.Text = res.Get("MatchWholeWord");
  91. btnOk.Text = res.Get("FindNext");
  92. btnCancel.Text = Res.Get("Buttons,Close");
  93. }
  94. public PreviewSearchForm()
  95. {
  96. InitializeComponent();
  97. Localize();
  98. Init();
  99. }
  100. }
  101. }