-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSearchTextBox.cs
More file actions
196 lines (179 loc) · 6.07 KB
/
Copy pathSearchTextBox.cs
File metadata and controls
196 lines (179 loc) · 6.07 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//-----------------------------------------------------------------------
// <copyright file="SearchTextBox.cs" company="NoteFly">
// NoteFly a note application.
// Copyright (C) 2012 Tom
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
//-----------------------------------------------------------------------
namespace NoteFly
{
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
/// <summary>
/// A SearchTextBox control
/// </summary>
public partial class SearchTextBox : UserControl
{
/// <summary>
/// Initializes a new instance of the SearchTextBox class.
/// </summary>
public SearchTextBox()
{
this.InitializeComponent();
this.lblTextSearch.Text = Strings.T("search:");
this.tableLayoutPnlSearchbox.ColumnCount = 2;
this.btnKeywordClear.ForeColor = Color.Black;
}
/// <summary>
/// Set the tooltips for this control
/// </summary>
public void SetControlTooltip(ToolTip tooltip)
{
if (tooltip == null)
{
return;
}
tooltip.SetToolTip(this.btnKeywordClear, Strings.T("stop search"));
}
/// <summary>
/// SearchStartHandler delegate
/// </summary>
/// <param name="keywords">The keywords type to lookup as pluginname</param>
public delegate void SearchStartHandler(string keywords);
/// <summary>
/// SearchStopHandler delegate
/// </summary>
public delegate void SearchStopHandler();
/// <summary>
/// A search occur event.
/// </summary>
[Description("A search occur.")]
public event SearchStartHandler SearchStart;
/// <summary>
/// Keywords entered are cleared not searching anymore event.
/// </summary>
[Description("Keywords entered are cleared not searching anymore.")]
public event SearchStopHandler SearchStop;
/// <summary>
/// Gets a valeu indicating wherhera keyword is entered.
/// </summary>
public bool IsKeywordEntered
{
get
{
if (this.tbKeywords.TextLength <= 0)
{
return false;
}
else
{
return true;
}
}
}
/// <summary>
/// The content of this searchbox is cleared and not highlighted.
/// Display all items normal again.
/// </summary>
public void Clear()
{
this.timerStartAutoSearch.Stop();
this.tbKeywords.Clear();
this.tbKeywords.BackColor = SystemColors.Window;
this.tableLayoutPnlSearchbox.ColumnCount = 2;
if (this.SearchStop != null)
{
this.SearchStop();
}
}
/// <summary>
/// keyword is entered and wait time for search to start has expire
/// or enter is entered do a search now.
/// </summary>
private void DoSearch()
{
this.timerStartAutoSearch.Stop();
if (this.tbKeywords.TextLength > 0)
{
this.tbKeywords.BackColor = Color.LightYellow;
this.tableLayoutPnlSearchbox.ColumnCount = 3;
if (this.SearchStart != null)
{
this.SearchStart(this.tbKeywords.Text);
}
}
else
{
this.tbKeywords.BackColor = SystemColors.Window;
this.tableLayoutPnlSearchbox.ColumnCount = 2;
}
}
/// <summary>
/// Reset the timer to start a search lookup.
/// </summary>
private void ResetAutoSearchDelay()
{
this.timerStartAutoSearch.Stop();
this.tbKeywords.BackColor = SystemColors.Window;
this.timerStartAutoSearch.Start();
}
/// <summary>
/// Do a search
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void timerStartSearch_Tick(object sender, EventArgs e)
{
this.DoSearch();
}
/// <summary>
/// Key is released in this SearchTextBox
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Key event arguments</param>
private void tbKeywords_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.DoSearch();
}
else
{
this.ResetAutoSearchDelay();
}
if (this.tbKeywords.TextLength > 0)
{
this.btnKeywordClear.Visible = true;
}
else
{
this.btnKeywordClear.Visible = false;
this.SearchStop();
}
}
/// <summary>
/// The button for stop searching is clicked, clear search keyword in textbox.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnKeywordClear_Click(object sender, EventArgs e)
{
this.btnKeywordClear.Visible = false;
this.Clear();
}
}
}