コード例 #1
0
        public CustomCheckBoxAdapter(CustomCheckBoxRenderer renderer)
        {
            Verify.Argument.IsNotNull(renderer, "renderer");

            _checkBox = new CustomCheckBox()
            {
                Renderer = renderer,
            };
            _checkBox.IsCheckedChanged  += OnCheckBoxIsCheckedChanged;
            _checkBox.CheckStateChanged += OnCheckBoxCheckStateChanged;
        }
コード例 #2
0
        public override void Render(Graphics graphics, Rectangle clipRectangle, CustomCheckBox checkBox)
        {
            const int CheckBoxSize = 16;

            using (var brush = new SolidBrush(checkBox.BackColor))
            {
                graphics.FillRectangle(brush, clipRectangle);
            }
            bool  highlight;
            Color foregroundColor;

            if (checkBox.Enabled)
            {
                highlight       = checkBox.IsMouseOver || checkBox.Focused;
                foregroundColor = highlight ? ColorTable.ForegroundHighlight : ColorTable.Foreground;
            }
            else
            {
                highlight       = false;
                foregroundColor = ColorTable.ForegroundDisabled;
            }
            var rcCheckBox = new Rectangle(1, 1 + (checkBox.Height - CheckBoxSize) / 2, CheckBoxSize - 2, CheckBoxSize - 2);

            using (var brush = new SolidBrush(highlight ? ColorTable.CheckBackgroundHighlight : ColorTable.CheckBackground))
            {
                graphics.FillRectangle(brush, rcCheckBox);
            }
            rcCheckBox.X      -= 1;
            rcCheckBox.Y      -= 1;
            rcCheckBox.Width  += 1;
            rcCheckBox.Height += 1;
            if (highlight)
            {
                using (var pen = new Pen(ColorTable.CheckHighlight))
                {
                    graphics.DrawRectangle(pen, rcCheckBox);
                }
            }
            switch (checkBox.CheckState)
            {
            case CheckState.Checked:
            {
                var path = new Point[]
                {
                    new Point(4, 7 + rcCheckBox.Y),
                    new Point(6, 10 + rcCheckBox.Y),
                    new Point(11, 3 + rcCheckBox.Y),
                };
                var mode = graphics.SmoothingMode;
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                using (var pen = new Pen(foregroundColor, 1.7f))
                {
                    graphics.DrawLines(pen, path);
                }
                graphics.SmoothingMode = mode;
            }
            break;

            case CheckState.Indeterminate:
            {
                var rect = new Rectangle(rcCheckBox.X + 5, rcCheckBox.Y + 5, rcCheckBox.Width - 9, rcCheckBox.Height - 9);
                using (var brush = new SolidBrush(foregroundColor))
                {
                    graphics.FillRectangle(brush, rect);
                }
            }
            break;
            }
            int textOffset = 16;

            if (checkBox.Image != null)
            {
                var image = checkBox.Image;
                textOffset += image.Width + 4;
                graphics.DrawImage(image, new Rectangle(16 + 3, (checkBox.Height - image.Height) / 2, image.Width, image.Height));
            }
            var text = checkBox.Text;

            if (!string.IsNullOrWhiteSpace(text))
            {
                TextRenderer.DrawText(
                    graphics,
                    text,
                    checkBox.Font,
                    new Rectangle(textOffset, 0, checkBox.Width - textOffset, checkBox.Height),
                    foregroundColor,
                    TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);
            }
        }
コード例 #3
0
 public abstract void Render(Graphics graphics, Rectangle clipRectangle, CustomCheckBox checkBox);