// ========================================================================
        // Methods

        #region === Methods

        /// <summary>
        ///     Raises the <see cref="ComboBox.DrawItem" /> event.
        /// </summary>
        /// <param name="e">A <see cref="DrawItemEventArgs" /> that contains the event data. </param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();

            var item = e.Index >= 0 ? Items[e.Index] : null;

            ControlDrawHelper.DrawImageComboBoxItem(e.Graphics, item, ImageList, ImageSize, e.Bounds, Font, ForeColor);

            base.OnDrawItem(e);
        }
Exemple #2
0
        /// <summary>
        ///     Paints the current <see cref="DataGridViewImageComboBoxColumnCell" />.
        /// </summary>
        /// <param name="graphics">The <see cref="T:System.Drawing.Graphics" /> used to paint the cell.</param>
        /// <param name="clipBounds">
        ///     A <see cref="T:System.Drawing.Rectangle" /> that represents the area of the
        ///     <see cref="T:System.Windows.Forms.DataGridView" /> that needs to be repainted.
        /// </param>
        /// <param name="cellBounds">
        ///     A <see cref="T:System.Drawing.Rectangle" /> that contains the bounds of the cell that is being
        ///     painted.
        /// </param>
        /// <param name="rowIndex">The row index of the cell that is being painted.</param>
        /// <param name="elementState">
        ///     A bitwise combination of <see cref="T:System.Windows.Forms.DataGridViewElementStates" />
        ///     values that specifies the state of the cell.
        /// </param>
        /// <param name="value">The data of the cell that is being painted.</param>
        /// <param name="formattedValue">The formatted data of the cell that is being painted.</param>
        /// <param name="errorText">An error message that is associated with the cell.</param>
        /// <param name="cellStyle">
        ///     A <see cref="T:System.Windows.Forms.DataGridViewCellStyle" /> that contains formatting and
        ///     style information about the cell.
        /// </param>
        /// <param name="advancedBorderStyle">
        ///     A <see cref="T:System.Windows.Forms.DataGridViewAdvancedBorderStyle" /> that contains
        ///     border styles for the cell that is being painted.
        /// </param>
        /// <param name="paintParts">
        ///     A bitwise combination of the <see cref="T:System.Windows.Forms.DataGridViewPaintParts" />
        ///     values that specifies which parts of the cell need to be painted.
        /// </param>
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            //Call the base to draw the combo box itself.
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, null, errorText, cellStyle, advancedBorderStyle, paintParts);

            //Now we will draw the current content of the box.
            DataGridViewImageComboBoxColumn column = ( DataGridViewImageComboBoxColumn )OwningColumn;

            if (((paintParts & DataGridViewPaintParts.Background) != 0) || ((paintParts & DataGridViewPaintParts.All) != 0))
            {
                Rectangle rect = new Rectangle(cellBounds.X + 4, cellBounds.Y, cellBounds.Width - 4, cellBounds.Height - 1);
                ControlDrawHelper.DrawImageComboBoxItem(graphics, value, column.ImageList, column.ImageSize, rect, cellStyle.Font, cellStyle.ForeColor);
            }
        }