接上面
private void lbMain_Click(object sender, System.EventArgs e)
{
if (lbMain.SelectedItems.Count == 0)
return;
string strSel = lbMain.SelectedItem.ToString();
this.Text = strSel;
int iSel = this.FindStringExact(Text);
if (iSel != -1)
this.SelectedIndex = iSel;
lbMain.Visible = false;
}
protected override void OnTextChanged(EventArgs e)
{
if (!DesignMode)
{
if (isselect == true)
{
lbMain.Visible = false;
isselect = false;
base.OnTextChanged(e);
return;
}
if (Text == "")
{
lbMain.Visible = false;
base.OnTextChanged(e);
return;
}
if (!this.Parent.Controls.Contains(lbMain))
{
lbMain.Width = this.Width+50;
lbMain.Height = 200;
lbMain.Parent = this.Parent;
lbMain.Top = this.Top + this.Height + 1;
lbMain.Left = this.Left;
this.Parent.Controls.Add(lbMain);
lbMain.BringToFront();
}
ArrayList alFill = GetFillList(Text);
lbMain.Items.Clear();
base.OnTextChanged(e);
lbMain.Items.AddRange(alFill.ToArray());
if (lbMain.Items.Count > 0)
lbMain.SelectedIndex = 0;
if (!lbMain.Visible && this.Focused)
lbMain.Visible = true;
}
base.OnTextChanged(e); } protected override void OnLocationChanged(EventArgs e)
{
if (!DesignMode)
{
if (lbMain != null)
{
SetlbMainLocation();
}
}
} private void SetlbMainLocation()
{
lbMain.Visible = false;
lbMain.Width = this.Width+50;
lbMain.Height = 200;
lbMain.Top = this.Top + this.Height + 1;
lbMain.Left = this.Left;
lbMain.BringToFront();
} protected override void OnLeave(EventArgs e)
{
if (!DesignMode)
{
if (!lbMain.Focused && !this.Focused)
lbMain.Visible = false;
}
base.OnLeave(e);
}
protected override void OnDropDown(EventArgs e)
{
lbMain.Visible = false;
isselect = true;
base.OnDropDown(e);
} protected override void OnVisibleChanged(EventArgs e)
{
if (!DesignMode)
{
if (!this.Visible)
{
if (lbMain != null)
{
lbMain.Visible = false;
}
}
}
base.OnVisibleChanged(e);
} protected override void OnKeyDown(KeyEventArgs e)
{
if (lbMain.Visible)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left ||
e.KeyCode == Keys.Right || e.KeyCode == Keys.PageDown || e.KeyCode == Keys.PageUp)
{
lbMain_KeyDown(lbMain, e);
e.Handled = true;
}
else if (e.KeyCode == Keys.Enter)
{
lbMain_Click(lbMain, e);
e.Handled = true;
}
else if (e.KeyCode == Keys.Back)
{
if (this.Text == "")
{
lbMain.SelectedIndex = -1;
}
}
}
base.OnKeyDown(e);
} private void lbMain_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left || e.KeyCode == Keys.PageUp)
{
if (lbMain.SelectedIndex > 0)
lbMain.SelectedIndex = lbMain.SelectedIndex - 1;
}
else if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right || e.KeyCode == Keys.PageDown)
{
if (lbMain.SelectedIndex < lbMain.Items.Count - 1)
lbMain.SelectedIndex = lbMain.SelectedIndex + 1;
}
} private void UComboBoxEx_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (!DesignMode)
{
lbMain.Visible = false;
}
} static public string GetChineseSpell(string strText)
{
int len = strText.Length;
string myStr = "";
for (int i = 0; i < len; i++)
{
myStr += getSpell(strText.Substring(i, 1));
}
return myStr;
} static public string getSpell(string cnChar)
{
byte[] arrCN = Encoding.Default.GetBytes(cnChar);
if (arrCN.Length > 1)
{
int area = (short)arrCN[0];
int pos = (short)arrCN[1];
int code = (area << 8) + pos;
int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
for (int i = 0; i < 26; i++)
{
int max = 55290;
if (i != 25) max = areacode[i + 1];
if (areacode[i] <= code && code < max)
{
return Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
}
}
return "*";
}
else
return cnChar;
}
}
}
private void lbMain_Click(object sender, System.EventArgs e)
{
if (lbMain.SelectedItems.Count == 0)
return;
string strSel = lbMain.SelectedItem.ToString();
this.Text = strSel;
int iSel = this.FindStringExact(Text);
if (iSel != -1)
this.SelectedIndex = iSel;
lbMain.Visible = false;
}
protected override void OnTextChanged(EventArgs e)
{
if (!DesignMode)
{
if (isselect == true)
{
lbMain.Visible = false;
isselect = false;
base.OnTextChanged(e);
return;
}
if (Text == "")
{
lbMain.Visible = false;
base.OnTextChanged(e);
return;
}
if (!this.Parent.Controls.Contains(lbMain))
{
lbMain.Width = this.Width+50;
lbMain.Height = 200;
lbMain.Parent = this.Parent;
lbMain.Top = this.Top + this.Height + 1;
lbMain.Left = this.Left;
this.Parent.Controls.Add(lbMain);
lbMain.BringToFront();
}
ArrayList alFill = GetFillList(Text);
lbMain.Items.Clear();
base.OnTextChanged(e);
lbMain.Items.AddRange(alFill.ToArray());
if (lbMain.Items.Count > 0)
lbMain.SelectedIndex = 0;
if (!lbMain.Visible && this.Focused)
lbMain.Visible = true;
}
base.OnTextChanged(e); } protected override void OnLocationChanged(EventArgs e)
{
if (!DesignMode)
{
if (lbMain != null)
{
SetlbMainLocation();
}
}
} private void SetlbMainLocation()
{
lbMain.Visible = false;
lbMain.Width = this.Width+50;
lbMain.Height = 200;
lbMain.Top = this.Top + this.Height + 1;
lbMain.Left = this.Left;
lbMain.BringToFront();
} protected override void OnLeave(EventArgs e)
{
if (!DesignMode)
{
if (!lbMain.Focused && !this.Focused)
lbMain.Visible = false;
}
base.OnLeave(e);
}
protected override void OnDropDown(EventArgs e)
{
lbMain.Visible = false;
isselect = true;
base.OnDropDown(e);
} protected override void OnVisibleChanged(EventArgs e)
{
if (!DesignMode)
{
if (!this.Visible)
{
if (lbMain != null)
{
lbMain.Visible = false;
}
}
}
base.OnVisibleChanged(e);
} protected override void OnKeyDown(KeyEventArgs e)
{
if (lbMain.Visible)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left ||
e.KeyCode == Keys.Right || e.KeyCode == Keys.PageDown || e.KeyCode == Keys.PageUp)
{
lbMain_KeyDown(lbMain, e);
e.Handled = true;
}
else if (e.KeyCode == Keys.Enter)
{
lbMain_Click(lbMain, e);
e.Handled = true;
}
else if (e.KeyCode == Keys.Back)
{
if (this.Text == "")
{
lbMain.SelectedIndex = -1;
}
}
}
base.OnKeyDown(e);
} private void lbMain_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left || e.KeyCode == Keys.PageUp)
{
if (lbMain.SelectedIndex > 0)
lbMain.SelectedIndex = lbMain.SelectedIndex - 1;
}
else if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right || e.KeyCode == Keys.PageDown)
{
if (lbMain.SelectedIndex < lbMain.Items.Count - 1)
lbMain.SelectedIndex = lbMain.SelectedIndex + 1;
}
} private void UComboBoxEx_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (!DesignMode)
{
lbMain.Visible = false;
}
} static public string GetChineseSpell(string strText)
{
int len = strText.Length;
string myStr = "";
for (int i = 0; i < len; i++)
{
myStr += getSpell(strText.Substring(i, 1));
}
return myStr;
} static public string getSpell(string cnChar)
{
byte[] arrCN = Encoding.Default.GetBytes(cnChar);
if (arrCN.Length > 1)
{
int area = (short)arrCN[0];
int pos = (short)arrCN[1];
int code = (area << 8) + pos;
int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
for (int i = 0; i < 26; i++)
{
int max = 55290;
if (i != 25) max = areacode[i + 1];
if (areacode[i] <= code && code < max)
{
return Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
}
}
return "*";
}
else
return cnChar;
}
}
}
解决方案 »
- .net 3.5 4.0版本下如何把缓存存在硬盘上 而不是内存中?
- C#添加新记录到access
- 奇了怪了 MFC都没碰到这种事情 SOCKET端口问题
- 文件“D:\Program Files\Microsoft Visual Studio 8\Common7\IDE\aaa.zip”正由另一进程使用,因此该进程无法访问该文件。
- Microsoft Excel 11.0 Object Library 的预编译宏是什么?
- 请教winforms下的checkboxlist
- 用findwindow如何找到窗口的句柄(其中类名和标题都在变化)
- 大家都来看看这个小问题,关于DataTimePicker和SQL结合
- 求教:关于C#应用问题!
- 在给toolbar上加上图标时遇到的问题!
- 为啥我的datagridview只能输入正整数?
- 急!C# 知道内存地址,如何读取数据显示到窗口?
AutoCompleteMode的属性设置显示为SuggestAppend
AutoCompleteSource的属性设置显示为ListItems这样设置可以实现输入内容,自动匹配combobox的全部内容,符合的给与显示不知道是否可以满足你的需求