Ejemplo n.º 1
0
 //重绘
 protected override void OnPaint(PaintEventArgs e)
 {
     base.OnPaint(e);
     for (int i = 0; i < Items.Count; i++)
     {
         MyListBoxItem item = Items[i] as MyListBoxItem;
         if (item != null)
         {
             Rectangle bound = GetItemRectangle(i);
             if (i == this.SelectedIndex)//选中项
             {
                 e.Graphics.FillRectangle(Brushes.Gray, bound);
                 e.Graphics.DrawImage(item.img, new Rectangle(bound.Left + 5, bound.Top + 6, 40, 48));
                 e.Graphics.DrawString("   使用者:" + item.userName + "                               所属部门:" + item.department, new Font("微软雅黑", 10), Brushes.White, new PointF(bound.Left + 5 + 50, bound.Top + 6));
                 e.Graphics.DrawString("   计算机编号:" + item.id + "                 IP:" + item.ip, new Font("微软雅黑", 11), Brushes.White, new PointF(bound.Left + 5 + 50, bound.Top + 20 + 6));
             }
             else if (item == UnderMouseItem) //鼠标滑过
             {
                 e.Graphics.FillRectangle(Brushes.Ivory, bound);
                 e.Graphics.DrawImage(item.img, new Rectangle(bound.Left + 5, bound.Top + 6, 40, 48));
                 e.Graphics.DrawString("    使用者:" + item.userName + "                            所属部门:" + item.department, new Font("微软雅黑", 10), Brushes.Black, new PointF(bound.Left + 5 + 50, bound.Top + 6));
                 e.Graphics.DrawString("    计算机编号:" + item.id + "                   IP:" + item.ip, new Font("微软雅黑", 11), Brushes.Black, new PointF(bound.Left + 5 + 50, bound.Top + 20 + 6));
             }
             else  //正常项
             {
                 e.Graphics.DrawImage(item.img, new Rectangle(bound.Left + 5, bound.Top + 6, 40, 48));
                 e.Graphics.DrawString("   使用者:" + item.userName + "                           所属部门:" + item.department, new Font("微软雅黑", 10), Brushes.Black, new PointF(bound.Left + 5 + 50, bound.Top + 6));
                 e.Graphics.DrawString("   计算机编号:" + item.id + "                   IP:" + item.ip, new Font("微软雅黑", 11), Brushes.Black, new PointF(bound.Left + 5 + 50, bound.Top + 20 + 6));
             }
         }
     }
 }
Ejemplo n.º 2
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     base.OnMouseMove(e);
     for (int i = 0; i < Items.Count; ++i)
     {
         Rectangle rect = this.GetItemRectangle(i);
         if (rect.Contains(e.Location))
         {
             UnderMouseItem = Items[i] as MyListBoxItem;
             Invalidate();
             break;
         }
     }
 }
Ejemplo n.º 3
0
 //设置各项高度
 protected override void OnMeasureItem(MeasureItemEventArgs e)
 {
     try
     {
         if (e.Index >= 0)
         {
             base.OnMeasureItem(e);
             MyListBoxItem i = Items[e.Index] as MyListBoxItem;
             if (i != null)
             {
                 e.ItemHeight = 60;
             }
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 4
0
        //
        //查询在线客机
        //返回:在线客机列表
        //
        public List <MyListBoxItem> getComputer()
        {
            MySqlConnection      mycon  = getMySqlCon();
            MySqlDataReader      reader = null;
            List <MyListBoxItem> items  = new List <MyListBoxItem>();
            MyListBoxItem        item   = null;

            try
            {
                if (mycon != null)
                {
                    mycon.Open();
                    Console.WriteLine("数据库user_LoginInfo打开成功!!!");
                    String       sql          = "select * from user_LoginInfo where department not like '%管理员%'";
                    MySqlCommand mySqlCommand = new MySqlCommand(sql, mycon);
                    reader = mySqlCommand.ExecuteReader();
                    while (reader.Read())
                    {
                        if (reader.HasRows)
                        {
                            if (reader.GetInt32("isOnline") != 0)
                            {
                                item = new MyListBoxItem(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), Resources.test);
                                items.Add(item);
                            }
                        }
                    }
                    Console.WriteLine("数据库user_LoginInfo读取成功!!!");
                    return(items);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("查询失败了!错误:" + e.Message);
                return(null);
            }
            finally
            {
                reader.Close();
                mycon.Close();
            }
            return(items);
        }