/*
2014年7月8日19:56:45
*/
namespace System.Windows.Forms
{
using System;
using System.Drawing;
public partial class SearchBox : UserControl
{
public SearchBox()
{
InitializeComponent();
}
public new string Text
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
public AutoCompleteStringCollection AutoCompleteCustomSource
{
get { return textBox1.AutoCompleteCustomSource; }
set { textBox1.AutoCompleteCustomSource = value; }
}
public delegate void EventHandler(object sender, EventArgs e);
public event EventHandler SearchClick;
protected void OnSearchButtonClick(object sender, EventArgs e)
{
if (SearchClick != null)
SearchClick(sender, e);
}
#region Implement
private void SearchBox_Load(object sender, EventArgs e)
{
textBox1.Text = "搜索";
textBox1.GotFocus += new System.EventHandler(textBox1_GotFocus);
textBox1.LostFocus += new System.EventHandler(textBox1_LostFocus);
XButton1.Visible = false;
}
void textBox1_GotFocus(object sender, EventArgs e)
{
borderColor1.BackColor = Color.FromArgb(51, 153, 255);
textBox1.SelectAll();
if (textBox1.Text == "搜索")
textBox1.Text = "";
}
void textBox1_LostFocus(object sender, EventArgs e)
{
borderColor1.BackColor = Color.FromArgb(171, 173, 179);
if (textBox1.Text == "")
{
textBox1.Text = "搜索";
XButton1.Visible = false;
}
}
private void textBox1_Enter(object sender, EventArgs e)
{
textBox1.Font = new System.Drawing.Font("Courier New", 10.5F, FontStyle.Regular);
}
//搜索
private void textBox1_Leave(object sender, EventArgs e)
{
if (textBox1.Text == "搜索")
textBox1.Font = new System.Drawing.Font("Courier New", 10.5F, FontStyle.Italic);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
XButton1.Visible = (textBox1.Text.Trim() != "");
}
private void textBox1_DoubleClick(object sender, EventArgs e)
{
textBox1.SelectAll();
}
private void XButton1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox1.Focus();
}
private void SearchButton1_Click(object sender, EventArgs e)
{
OnSearchButtonClick(sender, e);
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
SearchButton1_Click(sender, e);
}
}
private void XButton1_MouseLeave(object sender, EventArgs e)
{
XButton1.Image = imageList1.Images[3];
}
private void XButton1_MouseEnter(object sender, EventArgs e)
{
XButton1.Image = imageList1.Images[4];
}
private void XButton1_MouseDown(object sender, MouseEventArgs e)
{
XButton1.Image = imageList1.Images[5];
}
private void SearchButton1_MouseLeave(object sender, EventArgs e)
{
SearchButton1.Image = imageList1.Images[0];
}
private void SearchButton1_MouseUp(object sender, MouseEventArgs e)
{
SearchButton1.Image = imageList1.Images[0];
}
private void SearchButton1_MouseEnter(object sender, EventArgs e)
{
SearchButton1.Image = imageList1.Images[1];
}
private void SearchButton1_MouseDown(object sender, MouseEventArgs e)
{
SearchButton1.Image = imageList1.Images[2];
}
#endregion
}
}