2008-12-2日c#窗体:今天做了很久的鼠标悬浮事件,结果明白应该是移动事件,不过去鼠标坐标的这个用法还将就。
Point position = Point.Empty;
private void lsBFilter_MouseMove(object sender, MouseEventArgs e)
{
position = new Point(e.X, e.Y);
int i = 0;
for (i = lsBFilter.Items.Count - 1; i > 0; i--)
{
if (position.Y >= i * lsBFilter.ItemHeight)
{
lsBFilter.SetSelected(i, true);
break;
}
if (position.Y < lsBFilter.ItemHeight)
{
lsBFilter.SetSelected(0, true);
}
}
}
private void txtBookName_MouseClick(object sender, MouseEventArgs e)
{
lsBFilter.ClearSelected();
lsBFilter.Visible = false;
}
第一次使用文本框和listbox实现方便的数据库查询
private void txtBookName_TextChanged(object sender, EventArgs e)
{
cboBook.SelectedIndex = -1;
cboClass.SelectedIndex = -1;
cboUsers.SelectedIndex = -1;
lsBFilter.Items.Clear();
if (txtBookName.Text.Trim() != "")
{
strSql = string.Format("select DISTINCT Booksname from BookInfo where Booksname like '%{0}%'", txtBookName.Text.Trim());
DBHelper.getDataTableA(strSql);
int i = 0;
while (DBHelper.NumF.Length > 0 && i < DBHelper.NumF.Length)
{
lsBFilter.Items.Add(DBHelper.NumF[i]);
i++;
}
if (DBHelper.NumF.Length > 0)
{
lsBFilter.SetBounds(txtBookName.Location.X, txtBookName.Location.Y + txtBookName.Height, txtBookName.Width, 4 * txtBookName.Height);
lsBFilter.ScrollAlwaysVisible = false;
lsBFilter.Visible = true;
}
lsBFilter.SetSelected(0, true);
}
if (txtBookName.Text.Trim() == "")
{
lsBFilter.Items.Clear();
lsBFilter.Visible = false;
}
}
Point position = Point.Empty;
private void lsBFilter_MouseMove(object sender, MouseEventArgs e)
{
position = new Point(e.X, e.Y);
int i = 0;
for (i = lsBFilter.Items.Count - 1; i > 0; i--)
{
if (position.Y >= i * lsBFilter.ItemHeight)
{
lsBFilter.SetSelected(i, true);
break;
}
if (position.Y < lsBFilter.ItemHeight)
{
lsBFilter.SetSelected(0, true);
}
}
}
private void txtBookName_MouseClick(object sender, MouseEventArgs e)
{
lsBFilter.ClearSelected();
lsBFilter.Visible = false;
}
第一次使用文本框和listbox实现方便的数据库查询
private void txtBookName_TextChanged(object sender, EventArgs e)
{
cboBook.SelectedIndex = -1;
cboClass.SelectedIndex = -1;
cboUsers.SelectedIndex = -1;
lsBFilter.Items.Clear();
if (txtBookName.Text.Trim() != "")
{
strSql = string.Format("select DISTINCT Booksname from BookInfo where Booksname like '%{0}%'", txtBookName.Text.Trim());
DBHelper.getDataTableA(strSql);
int i = 0;
while (DBHelper.NumF.Length > 0 && i < DBHelper.NumF.Length)
{
lsBFilter.Items.Add(DBHelper.NumF[i]);
i++;
}
if (DBHelper.NumF.Length > 0)
{
lsBFilter.SetBounds(txtBookName.Location.X, txtBookName.Location.Y + txtBookName.Height, txtBookName.Width, 4 * txtBookName.Height);
lsBFilter.ScrollAlwaysVisible = false;
lsBFilter.Visible = true;
}
lsBFilter.SetSelected(0, true);
}
if (txtBookName.Text.Trim() == "")
{
lsBFilter.Items.Clear();
lsBFilter.Visible = false;
}
}