Beispiel #1
0
        protected override void OnDrawItem(swf.DrawItemEventArgs e)
        {
            if (e.State.HasFlag(swf.DrawItemState.ComboBoxEdit))
            {
                var bounds = e.Bounds;
                bounds.Inflate(2, 2);
                // only show the background color for the drop down, not for each item
                e.Graphics.FillRectangle(new sd.SolidBrush(BackColor), bounds);
            }
            else
            {
                e.DrawBackground();
            }

            if (e.Index >= 0)
            {
                var item    = Items[e.Index];
                var bounds  = e.Bounds;
                var etoitem = item as EtoComboBoxItem;
                var image   = etoitem?.Image;

                if (image != null)
                {
                    e.Graphics.DrawImage(image.ToSD(new Size(16, 16)), bounds.X, bounds.Y, 16, 16);
                    bounds.X     += 18;
                    bounds.Width -= 18;
                }

                string text = item?.ToString();

                var font = Font;
                if (FormatItem != null)
                {
                    var args = new DropDownFormatEventArgs(etoitem.Value, e.Index, font.ToEto());
                    FormatItem.Invoke(this, args);
                    font = args.Font.ToSD();
                }

                // Determine the forecolor based on whether or not the item is selected
                swf.TextRenderer.DrawText(e.Graphics, text, font, bounds, ForeColor, swf.TextFormatFlags.Left);
            }

            e.DrawFocusRectangle();
        }