|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using PopupControl;
namespace PopupTest
{
public partial class SearchControl : UserControl
{
SearchProviders searchProviders;
Popup popup;
public SearchControl()
{
InitializeComponent();
popup = new Popup(searchProviders = new SearchProviders());
borderLabel.Image = searchProviders.ProviderImage;
borderLabel.Text = searchProviders.ProviderName;
popup.Closed += popup_Closed;
searchProviders.ProviderChanged += fireSearch_Event;
}
public event EventHandler<StringEventArgs> Search;
private void popup_Closed(object sender, ToolStripDropDownClosedEventArgs e)
{
if (!textBox.Visible)
{
borderLabel.Image = searchProviders.ProviderImage;
}
borderLabel.Text = searchProviders.ProviderName;
}
private void borderLabel_MouseDown(object sender, MouseEventArgs e)
{
textBox.Visible = true;
textBox.Focus();
}
private void buttonDropDown_Click(object sender, EventArgs e)
{
popup.Width = Width;
popup.Show(this);
}
private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = false;
if (e.KeyChar == '\r')
{
e.Handled = true;
FireSearch();
}
}
private void fireSearch_Event(object sender, EventArgs e)
{
FireSearch();
}
private void FireSearch()
{
if (textBox.Text.Length > 0 && Search != null)
{
Search(this, new StringEventArgs(searchProviders.SearchString + textBox.Text.Replace(' ', '+')));
}
}
private void textBox_Enter(object sender, EventArgs e)
{
borderLabel.Image = null;
}
private void textBox_Leave(object sender, EventArgs e)
{
if (textBox.Text.Length == 0)
{
borderLabel.Image = searchProviders.ProviderImage;
textBox.Visible = false;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.