Beispiel #1
0
        private void ComboBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }


            Color foreColor = e.ForeColor;

            e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
            e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            if (e.State.HasFlag(DrawItemState.Focus) && !e.State.HasFlag(DrawItemState.ComboBoxEdit))
            {
                e.DrawBackground();
                e.DrawFocusRectangle();
            }
            else
            {
                using (Brush backgbrush = new SolidBrush(Color.WhiteSmoke))
                {
                    e.Graphics.FillRectangle(backgbrush, e.Bounds);
                    foreColor = Color.Black;
                }
            }
            using (Brush textbrush = new SolidBrush(foreColor))
            {
                e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(),
                                      e.Font, textbrush, e.Bounds.Height + 10, e.Bounds.Y,
                                      StringFormat.GenericTypographic);
            }
            var item = (FlagCountryItem)comboBox1.Items[e.Index];

            e.Graphics.DrawImage(VPNSettings.GetFlag(item.code),
                                 new Rectangle(e.Bounds.Location,
                                               new Size(e.Bounds.Height - 2, e.Bounds.Height - 2)));
        }