コード例 #1
0
        void ComboBoxDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            ComboBox comboBox = (ComboBox)sender;

            e.DrawBackground();

            if (e.Index >= 0)
            {
                ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index];

                e.Graphics.DrawImageUnscaled(ClassBrowserIconService.ImageList.Images[item.IconIndex],
                                             new Point(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height - ClassBrowserIconService.ImageList.ImageSize.Height) / 2));
                Rectangle drawingRect = new Rectangle(e.Bounds.X + ClassBrowserIconService.ImageList.ImageSize.Width,
                                                      e.Bounds.Y,
                                                      e.Bounds.Width - ClassBrowserIconService.ImageList.ImageSize.Width,
                                                      e.Bounds.Height);

                Brush drawItemBrush = SystemBrushes.WindowText;
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    drawItemBrush = SystemBrushes.HighlightText;
                }
                if (!item.IsInCurrentPart)
                {
                    drawItemBrush = SystemBrushes.ControlDark;
                }
                else if (e.State == DrawItemState.ComboBoxEdit && !item.IsInside(textAreaControl.ActiveTextAreaControl.Caret.Line))
                {
                    drawItemBrush = SystemBrushes.ControlDark;
                }
                e.Graphics.DrawString(item.ToString(),
                                      font,
                                      drawItemBrush,
                                      drawingRect,
                                      drawStringFormat);
            }
            e.DrawFocusRectangle();
        }