namespace Costaco.CTN.Controls
{
/// <summary>
/// ComboBox 的摘要說明。
/// </summary>
public class ComboBox : System.Windows.Forms.ComboBox
{
#region 字段
/// <summary>
/// 表示最近一次的用戶交互操作是否是鍵盤操作。
/// </summary>
private bool isKeyPressed;
/// <summary>
/// 表示是否啟用自動完成功能。
/// </summary>
private bool autoComplete = true;
#endregion
#region 屬性
/// <summary>
/// 獲取是否啟用自動完成功能。
/// </summary>
//[Bindable(true), Browsable(true), SRCategory(SR.CatBehavior), SRDescription(SR.ComboBoxAutoCompleteDescr)]
public bool AutoComplete
{
get
{
return autoComplete;
}
set
{
autoComplete = value;
}
}
#endregion
#region 構造函數
/// <summary>
///
/// </summary>
public ComboBox()
{
isKeyPressed = false;
autoComplete = true;
}
#endregion
#region 保護方法
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnTextChanged(EventArgs e)
{
bool flag = isKeyPressed;
isKeyPressed = false;
if (DropDownStyle != System.Windows.Forms.ComboBoxStyle.DropDown)
{
base.OnTextChanged(e);
return;
}
if (!flag)
{
base.OnTextChanged(e);
; return;
}
if (!autoComplete)
{
base.OnTextChanged(e);
return;
}
BeginUpdate();
string newText = Text;
if (newText != "")
{
if (FindStringExact(newText) != -1)
{
if (DroppedDown)
{
DroppedDown = false;
}
}
else if (FindString(newText) != -1)
{
DroppedDown = true;
Text = newText;
Select(newText.Length, 0);
}
}
else if (DroppedDown)
{
DroppedDown = false;
}
EndUpdate();
base.OnTextChanged(e);
}
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{
isKeyPressed = true;
DroppedDown = true;
base.OnKeyPress(e);
}
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
isKeyPressed = false;/> DroppedDown = true;
base.OnMouseDown(e);
}
#endregion
}
}
//[Bindable(true), Browsable(true), SRCategory(SR.CatBehavior), SRDescription(SR.ComboBoxAutoCompleteDescr)]
找不到引用的,哪位大蝦如果能幫忙的話,請給我留言
修改了一點點網絡上的代碼,默認自動完成