Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        internal void DrawItemInternal(DrawListViewItemEventArgs e)
        {
            if (base.View == View.Details)
            {
                return;
            }

            Graphics g = e.Graphics;

            ListViewItem item = e.Item;

            ListViewItemStates itemState = e.State;

            ImageList imageList = item.ImageList;

            e.DrawBackground();

            bool drawImageFlag = imageList != null && (item.ImageIndex != -1 || !string.IsNullOrEmpty(item.ImageKey));

            bool selectedFlag = (itemState & ListViewItemStates.Selected) != 0;

            if (drawImageFlag)
            {
                DrawImage(g, item, selectedFlag);
            }

            if (!string.IsNullOrEmpty(item.Text))
            {
                Rectangle textRect = item.GetBounds(ItemBoundsPortion.Label);

                this.DrawBackground(g, e.ItemIndex, textRect, selectedFlag);

                this.DrawText(g, item, textRect, selectedFlag);
            }
        }
        /// <summary>
        ///  Creates a new DrawListViewSubItemEventArgs with the given parameters.
        /// </summary>
        public DrawListViewSubItemEventArgs(
            Graphics graphics,
            Rectangle bounds,
            ListViewItem?item,
            ListViewItem.ListViewSubItem?subItem,
            int itemIndex,
            int columnIndex,
            ColumnHeader?header,
            ListViewItemStates itemState)
        {
            Graphics = graphics ?? throw new ArgumentNullException(nameof(graphics));

            if (itemIndex == -1)
            {
                if (item is null)
                {
                    throw new ArgumentNullException(nameof(item));
                }
            }
            else if (subItem is null)
            {
                throw new ArgumentNullException(nameof(subItem));
            }

            Bounds      = bounds;
            Item        = item;
            SubItem     = subItem;
            ItemIndex   = itemIndex;
            ColumnIndex = columnIndex;
            Header      = header;
            ItemState   = itemState;
        }
        /// <summary>
        ///  Creates a new DrawListViewSubItemEventArgs with the given parameters.
        /// </summary>
        public DrawListViewSubItemEventArgs(
            Graphics graphics,
            Rectangle bounds,
            ListViewItem?item,
            ListViewItem.ListViewSubItem?subItem,
            int itemIndex,
            int columnIndex,
            ColumnHeader?header,
            ListViewItemStates itemState)
        {
            Graphics = graphics.OrThrowIfNull();

            if (itemIndex == -1)
            {
                ArgumentNullException.ThrowIfNull(item);
            }
            else
            {
                ArgumentNullException.ThrowIfNull(subItem);
            }

            Bounds      = bounds;
            Item        = item;
            SubItem     = subItem;
            ItemIndex   = itemIndex;
            ColumnIndex = columnIndex;
            Header      = header;
            ItemState   = itemState;
        }
Example #4
0
        protected override void OnDrawItem(DrawListViewItemEventArgs e)
        {
            //base.OnDrawItem(e);
            if (base.View == View.Details)
            {
                return;
            }
            Graphics           g         = e.Graphics;
            ListViewItem       item      = e.Item;
            ListViewItemStates itemState = e.State;
            ImageList          imageList = item.ImageList;

            e.DrawBackground();

            bool drawImage = (imageList != null) && (item.ImageIndex != -1 || string.IsNullOrEmpty(item.ImageKey));
            bool selected  = (itemState & ListViewItemStates.Selected) != 0;

            if (drawImage)
            {
                this.DrawImage(g, item, selected);
            }
            if (!string.IsNullOrEmpty(item.Text))
            {
                Rectangle textRect = item.GetBounds(ItemBoundsPortion.Label);
                this.DrawBackground(g, item.Index, textRect, selected);
                this.DrawText(g, item, textRect, selected);
            }
        }
Example #5
0
 private void HeaderPressedOffset(ref Rectangle rect, ListViewItemStates State)
 {
     //min rect height for SystemColors (Theme disabled)
     if ((int)rect.Height > (int)15)
     {
         //Draw Normal
         if (State == ListViewItemStates.Selected)
         {
             rect.Offset(3, 3);
         }
         else
         {
             rect.Offset(2, 2);
         }
     }
     else
     {
         //draw a little up
         if (State == ListViewItemStates.Selected)
         {
             rect.Offset(3, 2);
         }
         else
         {
             rect.Offset(2, 1);
         }
     }
 }
        internal void SetItemState(int index, uint data, ListViewItemStates mask)
        {
            var _ms_lvi = new LVITEMA();

            _ms_lvi.stateMask = mask;
            _ms_lvi.state     = data;
            SendMessage(Handle, ListViewMessages.LVM_SETITEMSTATE, index, ref _ms_lvi);
        }
Example #7
0
 /// <summary>
 /// Creates a new DrawListViewItemEventArgs with the given parameters.
 /// </summary>
 public DrawListViewItemEventArgs(Graphics graphics, ListViewItem item, Rectangle bounds, int itemIndex, ListViewItemStates state)
 {
     Graphics  = graphics;
     Item      = item;
     Bounds    = bounds;
     ItemIndex = itemIndex;
     State     = state;
 }
Example #8
0
 /// <summary>
 /// Creates a new DrawListViewItemEventArgs with the given parameters.
 /// </summary>
 public DrawListViewItemEventArgs(Graphics graphics, ListViewItem item, Rectangle bounds, int itemIndex, ListViewItemStates state)
 {
     Graphics  = graphics ?? throw new ArgumentNullException(nameof(graphics));
     Item      = item ?? throw new ArgumentNullException(nameof(item));
     Bounds    = bounds;
     ItemIndex = itemIndex;
     State     = state;
 }
Example #9
0
 public void DrawFocusRectangle_HasGraphics_Success(ListViewItemStates itemState)
 {
     using (var image = new Bitmap(10, 10))
         using (Graphics graphics = Graphics.FromImage(image))
         {
             var e = new DrawListViewSubItemEventArgs(graphics, new Rectangle(1, 2, 3, 4), new ListViewItem(), new ListViewItem.ListViewSubItem(), 0, 0, new ColumnHeader(), itemState);
             e.DrawFocusRectangle(new Rectangle(1, 2, 3, 4));
         }
 }
 public DrawListViewItemEventArgs(System.Drawing.Graphics graphics, ListViewItem item, Rectangle bounds, int itemIndex, ListViewItemStates state)
 {
     this.graphics = graphics;
     this.item = item;
     this.bounds = bounds;
     this.itemIndex = itemIndex;
     this.state = state;
     this.drawDefault = false;
 }
 public DrawListViewItemEventArgs(Graphics graphics, ListViewItem item,
                                  Rectangle_ bounds, int itemIndex, ListViewItemStates state)
 {
     this.graphics  = graphics;
     this.item      = item;
     this.bounds    = bounds;
     this.itemIndex = itemIndex;
     this.state     = state;
 }
 public DrawListViewItemEventArgs (Graphics graphics, ListViewItem item,
                                 Rectangle bounds, int itemIndex, ListViewItemStates state)
 {
     this.graphics = graphics;
     this.item = item;
     this.bounds = bounds;
     this.itemIndex = itemIndex;
     this.state = state;
 }
 public DrawListViewItemEventArgs(System.Drawing.Graphics graphics, ListViewItem item, Rectangle bounds, int itemIndex, ListViewItemStates state)
 {
     this.graphics    = graphics;
     this.item        = item;
     this.bounds      = bounds;
     this.itemIndex   = itemIndex;
     this.state       = state;
     this.drawDefault = false;
 }
        protected override ListViewItemStates GetItemStates(ListViewItem item)
        {
            ListViewItemStates listViewItemStates = base.GetItemStates(item);

            if ((item as DataTreeListViewItem).IsExpanded)
            {
                listViewItemStates |= ListViewItemStates.Marked;
            }
            return(listViewItemStates);
        }
 public DrawListViewColumnHeaderEventArgs(System.Drawing.Graphics graphics, Rectangle bounds, int columnIndex, ColumnHeader header, ListViewItemStates state, Color foreColor, Color backColor, System.Drawing.Font font)
 {
     this.graphics = graphics;
     this.bounds = bounds;
     this.columnIndex = columnIndex;
     this.header = header;
     this.state = state;
     this.foreColor = foreColor;
     this.backColor = backColor;
     this.font = font;
 }
Example #16
0
 public DrawListViewColumnHeaderEventArgs(System.Drawing.Graphics graphics, Rectangle bounds, int columnIndex, ColumnHeader header, ListViewItemStates state, Color foreColor, Color backColor, System.Drawing.Font font)
 {
     this.graphics    = graphics;
     this.bounds      = bounds;
     this.columnIndex = columnIndex;
     this.header      = header;
     this.state       = state;
     this.foreColor   = foreColor;
     this.backColor   = backColor;
     this.font        = font;
 }
Example #17
0
 protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
 {
     base.OnDrawSubItem(e);
     if (base.View == View.Details && e.ItemIndex != -1)
     {
         Rectangle          bounds    = e.Bounds;
         ListViewItemStates itemState = e.ItemState;
         Graphics           graphics  = e.Graphics;
         GDIHelper.InitializeGraphics(graphics);
         Blend blend = new Blend();
         blend.Positions = new float[4]
         {
             0f,
             0.4f,
             0.7f,
             1f
         };
         blend.Factors = new float[4]
         {
             0f,
             0.3f,
             0.8f,
             0.2f
         };
         if ((itemState & ListViewItemStates.Selected) == ListViewItemStates.Selected)
         {
             Color selectedBeginColor = _SelectedBeginColor;
             Color selectedEndColor   = _SelectedEndColor;
             selectedBeginColor = SkinManager.CurrentSkin.HeightLightControlColor.First;
             selectedEndColor   = SkinManager.CurrentSkin.HeightLightControlColor.Second;
             blend.Factors      = SkinManager.CurrentSkin.HeightLightControlColor.Factors;
             blend.Positions    = SkinManager.CurrentSkin.HeightLightControlColor.Positions;
             GDIHelper.FillPath(graphics, new RoundRectangle(bounds, 0), selectedBeginColor, selectedEndColor, blend);
         }
         else
         {
             if (e.ColumnIndex == 0)
             {
                 bounds.Inflate(0, -1);
             }
             Color selectedBeginColor = (e.ItemIndex % 2 == 0) ? _RowBackColor1 : _RowBackColor2;
             Color selectedEndColor   = selectedBeginColor;
             GDIHelper.FillPath(graphics, new RoundRectangle(bounds, 0), selectedBeginColor, selectedEndColor, blend);
         }
         if (e.ColumnIndex == 0)
         {
             OnDrawFirstSubItem(e, graphics);
         }
         else
         {
             DrawNormalSubItem(e, graphics);
         }
     }
 }
 public DrawListViewSubItemEventArgs(System.Drawing.Graphics graphics, Rectangle bounds, ListViewItem item, ListViewItem.ListViewSubItem subItem, int itemIndex, int columnIndex, ColumnHeader header, ListViewItemStates itemState)
 {
     this.graphics    = graphics;
     this.bounds      = bounds;
     this.item        = item;
     this.subItem     = subItem;
     this.itemIndex   = itemIndex;
     this.columnIndex = columnIndex;
     this.header      = header;
     this.itemState   = itemState;
 }
 public DrawListViewSubItemEventArgs(System.Drawing.Graphics graphics, Rectangle bounds, ListViewItem item, ListViewItem.ListViewSubItem subItem, int itemIndex, int columnIndex, ColumnHeader header, ListViewItemStates itemState)
 {
     this.graphics = graphics;
     this.bounds = bounds;
     this.item = item;
     this.subItem = subItem;
     this.itemIndex = itemIndex;
     this.columnIndex = columnIndex;
     this.header = header;
     this.itemState = itemState;
 }
Example #20
0
 protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
 {
     if (!this.ContainsFocus && !_HideSelection)
     {
         ListViewItemStates status = e.Item.Selected ? ListViewItemStates.Selected : e.ItemState;
         base.OnDrawSubItem(new DrawListViewSubItemEventArgs(e.Graphics, e.Bounds, e.Item, e.SubItem, e.ItemIndex, e.ColumnIndex, e.Header, status));
     }
     else
     {
         base.OnDrawSubItem(e);
     }
 }
Example #21
0
 /// <summary>
 /// Creates a new DrawListViewSubItemEventArgs with the given parameters.
 /// </summary>
 public DrawListViewSubItemEventArgs(Graphics graphics, Rectangle bounds, ListViewItem item,
                                     ListViewItem.ListViewSubItem subItem, int itemIndex, int columnIndex,
                                     ColumnHeader header, ListViewItemStates itemState)
 {
     Graphics    = graphics;
     Bounds      = bounds;
     Item        = item;
     SubItem     = subItem;
     ItemIndex   = itemIndex;
     ColumnIndex = columnIndex;
     Header      = header;
     ItemState   = itemState;
 }
Example #22
0
 /// <summary>
 /// Creates a new DrawListViewColumnHeaderEventArgs with the given parameters.
 /// </summary>
 public DrawListViewColumnHeaderEventArgs(Graphics graphics, Rectangle bounds, int columnIndex,
                                          ColumnHeader header, ListViewItemStates state,
                                          Color foreColor, Color backColor, Font font)
 {
     Graphics    = graphics;
     Bounds      = bounds;
     ColumnIndex = columnIndex;
     Header      = header;
     State       = state;
     ForeColor   = foreColor;
     BackColor   = backColor;
     Font        = font;
 }
 public DrawListViewColumnHeaderEventArgs(Graphics graphics, Rectangle bounds, int columnIndex,
                                          ColumnHeader header, ListViewItemStates state,
                                          Color foreColor, Color backColor, Font font)
 {
     Graphics    = graphics ?? throw new ArgumentNullException(nameof(graphics));
     Bounds      = bounds;
     ColumnIndex = columnIndex;
     Header      = header;
     State       = state;
     ForeColor   = foreColor;
     BackColor   = backColor;
     Font        = font;
 }
Example #24
0
 protected override void OnDrawItem(DrawListViewItemEventArgs e)
 {
     base.FullRowSelect = _FullRowSelect;
     if (!this.ContainsFocus && !_HideSelection)
     {
         ListViewItemStates status = e.Item.Selected ? ListViewItemStates.Selected : e.State;
         base.OnDrawItem(new DrawListViewItemEventArgs(e.Graphics, e.Item, e.Bounds, e.ItemIndex, status));
     }
     else
     {
         base.OnDrawItem(e);
     }
 }
Example #25
0
        protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
        {
            base.OnDrawSubItem(e);
            if (View != View.Details || e.ItemIndex == -1)
            {
                return;
            }

            Rectangle          bounds    = e.Bounds;
            ListViewItemStates itemState = e.ItemState;
            Graphics           g         = e.Graphics;

            GDIHelper.InitializeGraphics(g);
            Blend blen = new Blend();

            blen.Positions = new float[] { 0f, 0.4f, 0.7f, 1f };
            blen.Factors   = new float[] { 0f, 0.3f, 0.8f, 0.2f };
            Color c1, c2;

            if ((itemState & ListViewItemStates.Selected) == ListViewItemStates.Selected)
            {
                c1 = this._SelectedBeginColor;
                c2 = this._SelectedEndColor;
                //使用全局皮肤色彩,注意选择文字需要反色处理
                c1             = SkinManager.CurrentSkin.HeightLightControlColor.First;
                c2             = SkinManager.CurrentSkin.HeightLightControlColor.Second;
                blen.Factors   = SkinManager.CurrentSkin.HeightLightControlColor.Factors;
                blen.Positions = SkinManager.CurrentSkin.HeightLightControlColor.Positions;
                GDIHelper.FillPath(g, new RoundRectangle(bounds, 0), c1, c2, blen);
            }
            else
            {
                if (e.ColumnIndex == 0)
                {
                    bounds.Inflate(0, -1);
                }
                c1 = e.ItemIndex % 2 == 0 ? this._RowBackColor1 : this._RowBackColor2;
                c2 = c1;
                GDIHelper.FillPath(g, new RoundRectangle(bounds, 0), c1, c2, blen);
            }

            if (e.ColumnIndex == 0)
            {
                this.OnDrawFirstSubItem(e, g);
            }
            else
            {
                this.DrawNormalSubItem(e, g);
            }
        }
Example #26
0
        protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
        {
            base.OnDrawSubItem(e);

            if (View != View.LargeIcon)
            {
                return;
            }


            if (e.ItemIndex == -1)
            {
                return;
            }

            Rectangle          bounds    = e.Bounds;
            ListViewItemStates itemState = e.ItemState;
            Graphics           g         = e.Graphics;
            TextFormatFlags    flags     = TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter;



            if ((itemState & ListViewItemStates.Selected) == ListViewItemStates.Selected)
            {
            }
            else
            {
                Rectangle imageRect = new Rectangle(bounds.X + 4, bounds.Y + 2, bounds.Height - 4, bounds.Height - 4);
                Image     image     = e.Item.ImageIndex == -1 ? null : e.Item.ImageList.Images[e.Item.ImageIndex];

                if (image == null)
                {
                    e.DrawText(flags);
                    return;
                }
                g.DrawImage(image, imageRect);
                Rectangle textRect = new Rectangle(imageRect.Right + 3, bounds.Y, bounds.Width - imageRect.Right - 3, bounds.Height);

                TextRenderer.DrawText(g, e.Item.Text, e.Item.Font, textRect, e.Item.ForeColor, flags);

                return;
            }

            e.DrawText(flags);
        }
Example #27
0
 private bool IsInState(ListViewItemStates currentState, ListViewItemStates testState)
 {
     return ((currentState & testState) == testState);
 }
Example #28
0
        private void DrawListViewItem(Graphics g, ListViewItem item, ColumnHeader header, Font font, Color color, ListViewItemStates state)
        {
            bool hasImage = HasImage(item);
            // Draw Image if any
            if (hasImage && (header == null || header.Width > 4))
            {
                Rectangle rImage = item.GetBounds(ItemBoundsPortion.Icon);
                int index = item.ImageIndex;
                if (index < 0)
                    index = item.ImageList.Images.IndexOfKey(item.ImageKey);
                if (this.View != View.Details && this.View != View.List && this.StateImageList != null)
                    rImage.X += this.StateImageList.ImageSize.Width + 3;
                else if (this.View == View.SmallIcon && this.CheckBoxes && this.Groups.Count == 0)
                    rImage.X += this.SmallImageList.ImageSize.Width;
                else if (this.View == View.LargeIcon && (item.ImageList.ImageSize.Width < rImage.Width || item.ImageList.ImageSize.Height < rImage.Height))
                {
                    if (item.ImageList.ImageSize.Width < rImage.Width)
                        rImage.X += (rImage.Width - item.ImageList.ImageSize.Width) / 2;
                    if (item.ImageList.ImageSize.Height < rImage.Height)
                        rImage.Y += (rImage.Height - item.ImageList.ImageSize.Height) / 2;
                }

                Region oldClip = null;
                if (header != null && header.Width < rImage.Width)
                {
                    Rectangle rClip = rImage;
                    rClip.Width = header.Width;
                    oldClip = g.Clip;
                    g.SetClip(rClip);
                }
                if (rImage.Width > 2)
                {
                    g.DrawImage(item.ImageList.Images[index], rImage.Location); // item.ImageList.Draw(g, rImage.Location, index);
                }

                if (oldClip != null) g.Clip = oldClip;
            }

            // Draw text
            Rectangle rText = item.GetBounds(ItemBoundsPortion.Label);
            if (rText.Width > 2)
            {
                // Draw the item text for views other than the Details view.
                eTextFormat flags = eTextFormat.Left | eTextFormat.SingleLine | eTextFormat.NoPrefix;
                if (this.View == View.Tile && item.SubItems.Count > 1)
                    flags |= eTextFormat.Top;
                else
                    flags |= eTextFormat.VerticalCenter;
                if (this.View == View.LargeIcon)
                {
                    flags = eTextFormat.HorizontalCenter | eTextFormat.WordBreak | eTextFormat.EndEllipsis | eTextFormat.NoClipping;
                }
                else if (this.View == View.Details && header != null)
                {
                    flags |= eTextFormat.EndEllipsis;
                    if (header.TextAlign == HorizontalAlignment.Center)
                        flags |= eTextFormat.HorizontalCenter;
                    else if (header.TextAlign == HorizontalAlignment.Right)
                        flags |= eTextFormat.Right;

                    rText.X += 2;
                }
                else if (this.View == View.List || this.View == View.SmallIcon)
                    rText.X += 2;
                if (!BarFunctions.IsVista) rText.Inflate(0, 1);
                TextDrawing.DrawString(g, item.Text, font, color, rText, flags);

                if (this.View == View.Tile && item.SubItems.Count > 1)
                {
                    Size sz = TextDrawing.MeasureString(g, item.Text, font);
                    rText.Y += sz.Height;
                    rText.Height -= sz.Height;
                    Color c1 = item.SubItems[1].ForeColor;
                    if (!c1.IsEmpty && c1 != color)
                        color = c1;
                    else
                        color = SystemColors.ControlDarkDark;
                    TextDrawing.DrawString(g, item.SubItems[1].Text, font, color, rText, flags);
                }
            }

            if (this.View == View.Details || this.StateImageList != null)
            {
                if (this.StateImageList != null)
                {
                    if (item.StateImageIndex >= 0 && item.StateImageIndex < this.StateImageList.Images.Count)
                    {
                        Rectangle r = item.GetBounds(ItemBoundsPortion.Icon);
                        if (this.View == View.Details || this.View == View.List)
                            r.X -= 19;
                        else if (this.View == View.LargeIcon && r.Width > this.StateImageList.ImageSize.Width)
                        {
                            r.X += (r.Width - this.StateImageList.ImageSize.Width) / 2;
                            r.Y++;
                        }
                        else if (this.View == View.Tile && r.Height > this.StateImageList.ImageSize.Height)
                        {
                            r.Y += (r.Height - this.StateImageList.ImageSize.Height) / 2;
                            r.X++;
                        }
                        this.StateImageList.Draw(g, r.Location, item.StateImageIndex);
                    }
                }
            }

            if (this.CheckBoxes && (this.View == View.Details || this.View == View.List || this.View == View.SmallIcon || this.View == View.LargeIcon) && this.StateImageList == null)
            {
                Rectangle r = item.GetBounds(ItemBoundsPortion.Icon);
                if (this.View == View.LargeIcon)
                    r.X += (r.Width - m_CheckSignSize.Width) / 2 - 4;
                else if (this.View == View.List)
                    r.X -= 18;
                else if (this.View == View.SmallIcon && hasImage && this.Groups.Count > 0)
                    r.X -= 20;
                else if (this.View == View.SmallIcon)
                    r.X -= 3;
                else
                    r.X -= 21;
                Office2007CheckBoxItemPainter p = PainterFactory.CreateCheckBoxItemPainter(null);
                Office2007CheckBoxColorTable ctt = GetCheckBoxColorTable();
                Office2007CheckBoxStateColorTable ct = ctt.Default;
                if ((state & ListViewItemStates.Grayed) != 0 || !this.Enabled)
                    ct = ctt.Disabled;
                //else if ((state & ListViewItemStates.Hot) != 0)
                //    ct = ctt.MouseOver;

                p.PaintCheckBox(g, new Rectangle(r.X + 4, r.Y + (r.Height - m_CheckSignSize.Height) / 2, m_CheckSignSize.Width, m_CheckSignSize.Height),
                    ct, item.Checked ? CheckState.Checked : CheckState.Unchecked);
            }
        }
Example #29
0
        private void PaintSubItem(Graphics g, ListViewItem.ListViewSubItem subitem, Rectangle r, ListViewItemStates state, ColumnHeader header, Color itemBackColor, int columnIndex)
        {
            if (!IsInState(state, ListViewItemStates.Selected) && this.Enabled)
            {
                Rectangle rFill = r;
                //rFill.Height++;
                if (!subitem.BackColor.IsEmpty /*&& !(subitem.BackColor == this.BackColor && !itemBackColor.IsEmpty)*/)
                {
                    using (SolidBrush brush = new SolidBrush(subitem.BackColor))
                        g.FillRectangle(brush, rFill);
                }
                else if (!itemBackColor.IsEmpty)
                {
                    using (SolidBrush brush = new SolidBrush(itemBackColor))
                        g.FillRectangle(brush, rFill);
                }
            }

            eTextFormat flags = eTextFormat.Left | eTextFormat.SingleLine | eTextFormat.VerticalCenter | eTextFormat.EndEllipsis | eTextFormat.NoClipping | eTextFormat.NoPrefix;

            if (header != null)
            {
                if (header.TextAlign == HorizontalAlignment.Center)
                    flags |= eTextFormat.HorizontalCenter;
                else if (header.TextAlign == HorizontalAlignment.Right)
                    flags |= eTextFormat.Right;
            }

            Color foreColor = subitem.ForeColor;
            if (IsInState(state, ListViewItemStates.Selected) && this.Enabled && (columnIndex == 0 || this.FullRowSelect))
            {
                Office2007ListViewColorTable ct = GetColorTable();
                if (!ct.SelectionForeColor.IsEmpty)
                    foreColor = ct.SelectionForeColor;
            }
            if (!this.Enabled) foreColor = _DisabledForeColor.IsEmpty ? SystemColors.ControlDark : _DisabledForeColor;
            Rectangle rText = Rectangle.Inflate(r, -2, BarFunctions.IsVista ? 0 : 1); // Rectangle.Inflate(r, -sz.Width, 0);
            TextDrawing.DrawString(g, subitem.Text, subitem.Font, foreColor, rText, flags);
        }
Example #30
0
 public void DrawListViewItemEventArgs_DrawFocusRectangle_HasGraphicsFocused_Success(ListViewItem item, Rectangle bounds, ListViewItemStates state)
 {
     using (var image = new Bitmap(10, 10))
         using (Graphics graphics = Graphics.FromImage(image))
         {
             var e = new DrawListViewItemEventArgs(graphics, item, bounds, -1, state);
             e.DrawFocusRectangle();
         }
 }
Example #31
0
 public void DrawListViewItemEventArgs_Ctor_Graphics_ListViewItem_Rectangle_Int_ListViewItemStates(Rectangle bounds, int itemIndex, ListViewItemStates state)
 {
     using (var image = new Bitmap(10, 10))
         using (Graphics graphics = Graphics.FromImage(image))
         {
             var item = new ListViewItem();
             var e    = new DrawListViewItemEventArgs(graphics, item, bounds, itemIndex, state);
             Assert.Same(graphics, e.Graphics);
             Assert.Same(item, e.Item);
             Assert.Equal(bounds, e.Bounds);
             Assert.Equal(itemIndex, e.ItemIndex);
             Assert.Equal(state, e.State);
             Assert.False(e.DrawDefault);
         }
 }
 internal ListViewItemStateEventArgs(ListView owner, int itemIndex, ListViewItemStates state) : base(owner, itemIndex)
 {
     this.FState = state;
 }
Example #33
0
        private void DrawItemBackground(Graphics g, Rectangle r, ListViewItem item, ListViewItemStates state)
        {
            if (!this.Enabled) return;
            // Bug fix in ListView for this specific state
            if (state == 0 && item.Selected && this.View == View.Details && this.FullRowSelect && this.Focused)
                r.X++;

            if (!item.BackColor.IsEmpty)
            {
                using (SolidBrush brush = new SolidBrush(item.BackColor))
                {
                    g.FillRectangle(brush, r);
                }
            }
            bool selected = IsInState(state, ListViewItemStates.Selected) || state == 0 && item.Selected;
            if (selected)
            {
                Office2007ListViewColorTable ct = GetColorTable();
                // Draw the background for selected item.
                r.Height--;
                r.Width--;
                using (Pen pen = new Pen(ct.SelectionBorder))
                    g.DrawRectangle(pen, r);
                r.Height++;
                r.Width++;
                Rectangle ir = new Rectangle(r.X, r.Y + 1, r.Width, r.Height - 2);
                DisplayHelp.FillRectangle(g, ir, ct.SelectionBackground);
            }
            else if (IsInState(state, ListViewItemStates.Hot) && this.HotTracking)
            {
                Office2007Renderer rnd = this.GetRenderer() as Office2007Renderer;
                Office2007ButtonItemPainter.PaintBackground(g, rnd.ColorTable.ButtonItemColors[0].MouseOver, r, RoundRectangleShapeDescriptor.RectangleShape);
            }

            if (IsInState(state, ListViewItemStates.Focused) && (!IsInState(state, ListViewItemStates.Hot) && this.View != View.LargeIcon || selected))
            {
                Rectangle rFocus = item.Bounds;
                if (this.View == View.Details && !this.FullRowSelect || this.View == View.List)
                    rFocus = item.GetBounds(ItemBoundsPortion.Label);
                else if (this.View == View.Details && this.FullRowSelect)
                    rFocus = r;
                else if (this.View == View.SmallIcon)
                    rFocus = r;

                if (selected)
                {
                    rFocus.Y++;
                    rFocus.Height -= 2;
                }

                DrawFocusRectangle(g, rFocus, item);
            }
            else if (selected && this.View == View.Details && this.FullRowSelect && this.Focused) // Bug fix in ListView for this specific state
            {
                Rectangle rFocus = r;
                rFocus.Y++;
                rFocus.Height -= 2;
                Region oldClip = g.Clip;
                Rectangle rClip = rFocus;
                rClip.Width--;
                g.SetClip(rClip);
                DrawFocusRectangle(g, rFocus, item);
                g.Clip = oldClip;
            }
        }
 internal PostDrawListViewItemEventArgs(System.Drawing.Graphics g, ListView owner, int itemIndex, Rectangle bounds, ListViewItemStates state) : base(owner, itemIndex, state)
 {
     this.FGraphics = g;
     this.FBounds = bounds;
 }
Example #35
0
 public DrawListViewColumnHeaderEventArgs(Graphics graphics, Rectangle bounds, int columnIndex, ColumnHeader header, ListViewItemStates state, Color foreColor, Color backColor, Font font)
 {
     throw null;
 }
 internal PostDrawListViewSubItemEventArgs(Graphics g, ListView owner, int itemIndex, int subItemIndex, Rectangle bounds, ListViewItemStates state) : base(g, owner, itemIndex, bounds, state)
 {
     this.FSubItemIndex = subItemIndex;
 }
 // Constructors
 public DrawListViewColumnHeaderEventArgs(System.Drawing.Graphics graphics, System.Drawing.Rectangle bounds, int columnIndex, ColumnHeader header, ListViewItemStates state, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font font)
 {
 }
Example #38
0
        private void UpdateStateBit(object o, FieldInfo f, bool itemSelected, ListViewItemStates currentState)
        {
            bool stateSelected = (currentState & ListViewItemStates.Selected) != 0;

            if (itemSelected != stateSelected)
            {
                ListViewItemStates newState = currentState;
                if (itemSelected)
                {
                    newState |= ListViewItemStates.Selected;
                }
                else
                {
                    newState &= ~(ListViewItemStates.Selected);
                }
                try
                {
                    f.SetValue(o, newState);
                }
                catch { }
            }
        }
Example #39
0
		protected virtual bool DrawListViewSubItemOwnerDraw (Graphics dc, ListViewItem item, ListViewItemStates state, int index)
		{
			ListView control = item.ListView;
			ListViewItem.ListViewSubItem subitem = item.SubItems [index];

			DrawListViewSubItemEventArgs args = new DrawListViewSubItemEventArgs (dc, subitem.Bounds, item, 
					subitem, item.Index, index, control.Columns [index], state);
			control.OnDrawSubItem (args);
			
			return !args.DrawDefault;
		}
Example #40
0
        protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
        {
            //base.OnDrawSubItem(e);
            if (e.ItemIndex == -1)
            {
                return;
            }
            if (base.View == View.Details)
            {
                Rectangle          bounds    = e.Bounds;
                ListViewItemStates itemState = e.ItemState;
                Graphics           g         = e.Graphics;
                ListViewItem       item      = e.Item;
                bool selected   = (itemState & ListViewItemStates.Selected) != 0;
                bool drawImage  = false;
                bool fistItem   = false;
                int  imageIndex = -1;

                if (e.ColumnIndex == 0)
                {
                    fistItem = true;
                    if (item.ImageList != null)
                    {
                        if (item.ImageIndex != -1)
                        {
                            imageIndex = item.ImageIndex;
                        }
                        else if (!string.IsNullOrEmpty(item.ImageKey))
                        {
                            imageIndex = item.ImageList.Images.IndexOfKey(item.ImageKey);
                        }

                        if (imageIndex != -1)
                        {
                            drawImage = true;
                        }
                    }
                }

                Rectangle backRect  = bounds;
                Rectangle imageRect = Rectangle.Empty;
                if (drawImage)
                {
                    imageRect       = item.GetBounds(ItemBoundsPortion.Icon);
                    backRect        = item.GetBounds(ItemBoundsPortion.Label);
                    backRect.X     += 2;
                    backRect.Width -= 2;
                }
                Color textColor = Color.Black;
                if (selected && (base.FullRowSelect || (!base.FullRowSelect && fistItem)))
                {
                    backRect.Height--;
                    Color innerBorderColor = Color.FromArgb(150, 255, 255, 255);
                    //绘制选中区域
                    Image image = this.ItemBackgroundImage;
                    g.DrawImage(image, backRect, 0, 0, 5, image.Height, GraphicsUnit.Pixel);
                    g.DrawImage(image, backRect, 5, 0, image.Width - 10, image.Height, GraphicsUnit.Pixel);
                    g.DrawImage(image, backRect, image.Width - 5, 0, 5, image.Height, GraphicsUnit.Pixel);
                    textColor = Color.White;
                }
                else
                {
                    using (SolidBrush brush = new SolidBrush(this._itemBackgroundColor))
                    {
                        g.FillRectangle(brush, backRect);
                    }
                }
                TextFormatFlags flags = this.GetFormatFlags(e.Header.TextAlign);
                if (drawImage)//如果绘制图像
                {
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;

                    if (selected)
                    {
                        IntPtr hIcon = WinAPIDllImport.ImageList_GetIcon(item.ImageList.Handle, imageIndex, (int)ImageListDrawFlags.ILD_SELECTED);
                        g.DrawIcon(Icon.FromHandle(hIcon), imageRect.X, imageRect.Y + 2);
                        WinAPIDllImport.DestroyIcon(hIcon);
                    }
                    else
                    {
                        Image image = item.ImageList.Images[imageIndex];
                        g.DrawImage(image, imageRect.X, imageRect.Y + 2);
                    }
                    Rectangle textRect = new Rectangle(imageRect.Right + 3, bounds.Y, bounds.Width - imageRect.Right - 3, bounds.Height);
                    TextRenderer.DrawText(g, item.Text, item.Font, textRect, textColor, flags);
                }
                else
                {
                    bounds.X += 3;
                    TextRenderer.DrawText(g, e.SubItem.Text, e.SubItem.Font, bounds, textColor, flags);
                }
                if (base.CheckBoxes)
                {
                    if (e.Item.SubItems[0] == e.SubItem)
                    {
                        Size  sizeCheckBox  = CheckBoxRenderer.GetGlyphSize(e.Graphics, e.Item.Checked ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal : System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
                        Point checkBoxPoint = new Point(e.Bounds.X, e.Bounds.Top + 10);
                        CheckBoxRenderer.DrawCheckBox(e.Graphics, checkBoxPoint, e.Item.Checked ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal : System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
                    }
                }
            }
        }
Example #41
0
 internal void SetItemState(int index, uint data, ListViewItemStates mask)
 {
     LVITEMA _ms_lvi = new LVITEMA();
     _ms_lvi.stateMask = mask;
     _ms_lvi.state = data;
     SendMessage(this.Handle, ListViewMessages.LVM_SETITEMSTATE, index, ref _ms_lvi);
 }
        public void Ctor_Graphics_ListViewItem_Rectangle_Int_ListViewItemStates(Graphics graphics, ListViewItem item, Rectangle bounds, int itemIndex, ListViewItemStates state)
        {
            var e = new DrawListViewItemEventArgs(graphics, item, bounds, itemIndex, state);

            Assert.Equal(graphics, e.Graphics);
            Assert.Equal(item, e.Item);
            Assert.Equal(bounds, e.Bounds);
            Assert.Equal(itemIndex, e.ItemIndex);
            Assert.Equal(state, e.State);
            Assert.False(e.DrawDefault);
        }
 internal GetItemColorsEventArgs(ListView owner, int itemIndex, ListViewItemStates state, Color backColor, Color foreColor) : base(owner, itemIndex, state)
 {
     this.BackColor = backColor;
     this.ForeColor = foreColor;
 }
	// Constructors
	public DrawListViewSubItemEventArgs(System.Drawing.Graphics graphics, System.Drawing.Rectangle bounds, ListViewItem item, ListViewSubItem subItem, int itemIndex, int columnIndex, ColumnHeader header, ListViewItemStates itemState) {}
Example #45
0
 public void DrawListViewItemEventArgs_DrawText_InvokeTextFormatFlags(ListViewItem item, Rectangle bounds, ListViewItemStates state)
 {
     using (var image = new Bitmap(10, 10))
         using (Graphics graphics = Graphics.FromImage(image))
         {
             var e = new DrawListViewItemEventArgs(graphics, item, bounds, -1, state);
             e.DrawText(TextFormatFlags.Bottom);
         }
 }
	// Constructors
	public DrawListViewColumnHeaderEventArgs(System.Drawing.Graphics graphics, System.Drawing.Rectangle bounds, int columnIndex, ColumnHeader header, ListViewItemStates state, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Font font) {}
Example #47
0
 public void DrawListViewColumnHeaderEventArgs_DrawBackground_Invoke_Success(Rectangle bounds, ColumnHeader header, ListViewItemStates state, Color foreColor, Color backColor, Font font)
 {
     using (var image = new Bitmap(10, 10))
         using (Graphics graphics = Graphics.FromImage(image))
         {
             var e = new DrawListViewColumnHeaderEventArgs(graphics, bounds, -1, header, state, foreColor, backColor, font);
             e.DrawBackground();
         }
 }
	// Constructors
	public DrawListViewItemEventArgs(System.Drawing.Graphics graphics, ListViewItem item, System.Drawing.Rectangle bounds, int itemIndex, ListViewItemStates state) {}