Ejemplo n.º 1
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.ComboBox.DrawItem"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.DrawItemEventArgs"/> that contains the event data.</param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);

            TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.Left
                                    | TextFormatFlags.SingleLine
                                    | TextFormatFlags.VerticalCenter;

            if ((e.Index < 0) ||
                (e.Index >= Items.Count))
            {
                return;
            }

            if (GorgonFontEditorPlugIn.IsRightToLeft(this))
            {
                flags |= TextFormatFlags.RightToLeft;
            }

            e.DrawBackground();

            if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
            {
                e.DrawFocusRectangle();
            }

            string fontName = Items[e.Index].ToString();
            Font   font;

            if (!GorgonFontEditorPlugIn.CachedFonts.TryGetValue(fontName, out font))
            {
                font = Font;
            }

            e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            Size measure    = TextRenderer.MeasureText(e.Graphics, fontName, Font, e.Bounds.Size, flags);
            var  textBounds = new Rectangle(e.Bounds.Width - measure.Width + e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
            var  fontBounds = new Rectangle(e.Bounds.Left, e.Bounds.Top, textBounds.X - 2, e.Bounds.Height);

            TextRenderer.DrawText(e.Graphics, fontName, font, fontBounds, e.ForeColor, e.BackColor, flags);
            TextRenderer.DrawText(e.Graphics, fontName, Font, textBounds, e.ForeColor, e.BackColor, flags);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.ComboBox.DrawItem"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.DrawItemEventArgs"/> that contains the event data.</param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);

            TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix | TextFormatFlags.Left | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter;

            if ((e.Index < 0) || (e.Index >= Items.Count))
            {
                return;
            }

            if (GorgonFontEditorPlugIn.IsRightToLeft(this))
            {
                flags |= TextFormatFlags.RightToLeft;
            }

            e.DrawBackground();

            if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
            {
                e.DrawFocusRectangle();
            }

            string     patternName = Items[e.Index].ToString();
            HatchStyle style;

            if (!_patternList.TryGetValue(patternName, out style))
            {
                return;
            }

            e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            var textBounds    = new Rectangle(26 + e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
            var patternBounds = new Rectangle(e.Bounds.Left + 2, e.Bounds.Top + 2, 22, e.Bounds.Height - 4);

            using (Brush brush = new HatchBrush(style, e.ForeColor, e.BackColor))
            {
                TextRenderer.DrawText(e.Graphics, patternName, Font, textBounds, e.ForeColor, e.BackColor, flags);
                e.Graphics.FillRectangle(brush, patternBounds);
                e.Graphics.DrawRectangle(Pens.Black, patternBounds);
            }
        }