-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserControlSearch.cs
92 lines (78 loc) · 2.91 KB
/
UserControlSearch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Drawing;
using System.Windows.Forms;
namespace LogScraper
{
public partial class UserControlSearch : UserControl
{
public event Action<string, SearchDirectionUserControl, bool, bool, bool> Search;
public enum SearchDirectionUserControl
{
Forward,
Backward
}
public UserControlSearch()
{
InitializeComponent();
TxtSearch_Leave(null, null);
ToolTip.SetToolTip(chkWholeWordsOnly, "Alleen hele woorden zoeken");
ToolTip.SetToolTip(chkCaseSensitive, "Hoofdletter gevoelig zoeken");
ToolTip.SetToolTip(chkWrapAround, "Zoek verder vanaf het begin");
ToolTip.SetToolTip(btnSearchNext, "Volgende zoeken");
ToolTip.SetToolTip(btnSearchPrevious, "Vorige zoeken");
}
public void SetResultsFound(bool resultsFound)
{
lblNoResults.Visible = !resultsFound;
}
private void BtnSearchNext_Click(object sender, EventArgs e)
{
if (IsSearchEmpty()) return;
Search?.Invoke(txtSearch.Text, SearchDirectionUserControl.Forward, chkCaseSensitive.Checked, chkWholeWordsOnly.Checked, chkWrapAround.Checked);
}
private void BtnSearchPrevious_Click(object sender, EventArgs e)
{
if (IsSearchEmpty()) return;
Search?.Invoke(txtSearch.Text, SearchDirectionUserControl.Backward, chkCaseSensitive.Checked, chkWholeWordsOnly.Checked, chkWrapAround.Checked);
}
private bool IsSearchEmpty()
{
string search = txtSearch.Text.Trim();
if (string.IsNullOrEmpty(search) || search == DefaulSearchtText) return true;
return false;
}
private void TxtSearch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
BtnSearchNext_Click(sender, e);
e.Handled = true; // This prevents the system from processing the Enter key further
}
}
private void ChkCaseSensitive_CheckedChanged(object sender, EventArgs e)
{
txtSearch.Focus();
}
private void ChkWholeWordsOnly_CheckedChanged(object sender, EventArgs e)
{
txtSearch.Focus();
}
private const string DefaulSearchtText = "Zoeken...";
private void TxtSearch_Enter(object sender, EventArgs e)
{
if (txtSearch.Text == DefaulSearchtText)
{
txtSearch.Text = "";
txtSearch.ForeColor = SystemColors.ControlText;
}
}
private void TxtSearch_Leave(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(txtSearch.Text))
{
txtSearch.Text = DefaulSearchtText;
txtSearch.ForeColor = Color.DarkGray;
}
}
}
}