论坛首页 海阔天空论坛

我的程序员行程

浏览 1663 次
精华帖 (0) :: 良好帖 (0) :: 灌水帖 (0) :: 隐藏帖 (1)
作者 正文
   发表时间:2009-05-07   最后修改:2009-05-07
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;
            }
        }

论坛首页 海阔天空版

跳转论坛:
Global site tag (gtag.js) - Google Analytics