示例#1
0
 protected override void OnDrawItem(DrawItemEventArgs e)
 {
     if (e.Index < 0 || e.Index >= Items.Count)
     {
         return;
     }
     if (Items.Count == 0 && Focused)
     {
         ProtoListControlHelp.DrawFocusRectangle(e.Graphics, e.Bounds);
         return;
     }
     // 描绘背景颜色
     e.Graphics.FillRectangle(GetBackBrush(e), e.Bounds);
     if (GetFocused(e))
     {
         ProtoListControlHelp.DrawFocusRectangle(e.Graphics, e.Bounds);
     }
     // 描绘文字
     e.Graphics.DrawString(Items[e.Index].ToString(), Font, GetForeBrush(e), e.Bounds);
 }
示例#2
0
        protected override void OnDrawItem(DrawListViewItemEventArgs e)
        {
            if (e.ItemIndex < 0 || e.ItemIndex >= Items.Count)
            {
                return;
            }
            if (Items.Count == 0 && Focused)
            {
                ProtoListControlHelp.DrawFocusRectangle(e.Graphics, e.Bounds);
                return;
            }
            Rectangle Bounds = new Rectangle(e.Bounds.X, e.Bounds.Y, this.ClientSize.Width, e.Bounds.Height);

            // TODO:修正焦点条被截断的问题。
            // 描绘背景图形
            e.Graphics.FillRectangle(GetBackBrush(e), Bounds);
            if (GetFocused(e))
            {
                e.Graphics.FillRectangle(ProtoListControlHelp.GetFocusBrush(e.Bounds, BackColor), e.Bounds);
                ProtoListControlHelp.DrawFocusRectangle(e.Graphics, e.Bounds);
            }
            // 子类描绘调用
            foreach (ListViewItem.ListViewSubItem item in e.Item.SubItems)
            {
                OnDrawSubItem(new DrawListViewSubItemEventArgs(
                                  e.Graphics, item.Bounds, e.Item, item, e.ItemIndex, 0, null, e.State));
            }
            // 补齐剩余部分
            if (e.ItemIndex == Items.Count - 1)
            {
                int cy = e.Bounds.Y + e.Bounds.Height, count = e.ItemIndex % ProtoListControlHelp.DefaultBackColors.Count;
                while (cy <= this.ClientRectangle.Height)
                {
                    count = (count + 1) % ProtoListControlHelp.DefaultBackColors.Count;
                    SolidBrush ExtraBackBrush = new SolidBrush(ProtoListControlHelp.
                                                               CheckEnabled(ProtoListControlHelp.DefaultBackColors[count], Enabled));
                    e.Graphics.FillRectangle(ExtraBackBrush, new Rectangle(e.Bounds.X, cy, this.ClientSize.Width, e.Bounds.Height));
                    cy += e.Bounds.Height;
                }
            }
        }
示例#3
0
 protected void DrawFocusRectangle(Graphics graphics, Rectangle rect)
 {
     ProtoListControlHelp.DrawFocusRectangle(graphics, rect);
 }