Exemple #1
0
        private void cbPattern_DrawItem(object sender, DrawItemEventArgs e)
        {
            ComboBox cb = (ComboBox)sender;
            Graphics g  = e.Graphics;

            // Draw the background of the item.
            e.DrawBackground();
            Rectangle largerect = new Rectangle(e.Bounds.X, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1);

            try
            {
                switch (DrawUtils.FillModeFromIndex(e.Index))
                {
                case FillMode.None: ShowItemText(e, cb, g, largerect); break;

                case FillMode.Solid: ShowItemText(e, cb, g, largerect); break;

                case FillMode.LinearGradient:
                    using (LinearGradientBrush brush =
                               new LinearGradientBrush(largerect, fill.PatternColor, fill.Color,
                                                       DrawUtils.LinearGradientModeFromIndex(e.Index)))
                    {
                        g.FillRectangle(brush, largerect);
                    }
                    break;

                case FillMode.Hatch:
                    using (HatchBrush brush =
                               new HatchBrush(DrawUtils.HatchStyleFromIndex(e.Index),
                                              fill.PatternColor, fill.Color))
                    {
                        g.FillRectangle(brush, largerect);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} Exception caught.", ex);
                throw;
            }
            // Draw the focus rectangle if the mouse hovers over an item.
            e.DrawFocusRectangle();
        }