Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Draw the sub item.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="T:System.Windows.Forms.DrawListViewSubItemEventArgs"/>
        /// instance containing the event data.</param>
        /// ------------------------------------------------------------------------------------
        void CtrlDrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            if (e.ColumnIndex != m_styleColumn)
            {
                return;
            }

            Debug.Assert(e.ItemIndex != -1);

            ListViewItem item = e.Item;

            ListViewItem.ListViewSubItem subItem = e.SubItem;

            // Draw the icon only if we're not drawing a combo box's edit portion.
            int xOffset = 0;
            //if (e.ColumnIndex == m_styleColumn)

            //{
            // Get the item being drawn.
            StyleListItem styleItem;

            if (m_styleItemList.TryGetValue(subItem.Text, out styleItem))
            {
                // Determine what image to draw, considering the selection state of the item and
                // whether the item is a character style or a paragraph style.
                Image icon = GetCorrectIcon(styleItem, item.Selected && m_ctrl.Focused);

                e.Graphics.DrawImage(icon, e.Bounds.Left, e.Bounds.Top +
                                     (e.Bounds.Height - icon.Height) / 2);
                xOffset = icon.Width;
            }
            //}
            Rectangle bounds = e.Bounds;

            bounds.X     += xOffset;
            bounds.Width -= xOffset;

            // Draw the item's text, considering the item's selection state. Item text in the
            // edit portion will be drawn further left than those in the drop-down because text
            // in the edit portion doesn't have the icon to the left.
            TextRenderer.DrawText(e.Graphics, subItem.Text, m_ctrl.Font, bounds, ListViewControl.GetTextColor(e),
                                  TextFormatFlags.LeftAndRightPadding | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter);

            //e.Graphics.DrawString(subItem.Text, m_ctrl.Font,
            //    new SolidBrush(item.Selected ? SystemColors.HighlightText : SystemColors.WindowText),
            //    bounds);
        }