protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);

            if (this.Owner != null)
            {
                Color font_color = this.Enabled ? this.ForeColor : SystemColors.GrayText;
                Image draw_image = this.Enabled ? this.Image : ToolStripRenderer.CreateDisabledImage(this.Image);

                this.Owner.Renderer.DrawButtonBackground(new System.Windows.Forms.ToolStripItemRenderEventArgs(e.Graphics, this));

                Rectangle text_layout_rect;
                Rectangle image_layout_rect;

                this.CalculateTextAndImageRectangles(out text_layout_rect, out image_layout_rect);

                if (text_layout_rect != Rectangle.Empty)
                {
                    this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, font_color, this.Font, this.TextAlign));
                }
                if (image_layout_rect != Rectangle.Empty)
                {
                    this.Owner.Renderer.DrawItemImage(new System.Windows.Forms.ToolStripItemImageRenderEventArgs(e.Graphics, this, draw_image, image_layout_rect));
                }

                return;
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (this.Owner != null)
            {
                Color_ font_color = this.Enabled ? this.ForeColor : SystemColors.GrayText;
                Image  draw_image = this.Enabled ? this.Image : ToolStripRenderer.CreateDisabledImage(this.Image);

                this.Owner.Renderer.DrawSplitButton(new System.Windows.Forms.ToolStripItemRenderEventArgs(e.Graphics, this));

                Rectangle_ text_layout_rect;
                Rectangle_ image_layout_rect;

                Rectangle_ r = this.ContentRectangle;
                r.Width -= (this.drop_down_button_width + 1);

                this.CalculateTextAndImageRectangles(r, out text_layout_rect, out image_layout_rect);

                if (text_layout_rect != Rectangle_.Empty)
                {
                    this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, font_color, this.Font, this.TextAlign));
                }
                if (image_layout_rect != Rectangle_.Empty)
                {
                    this.Owner.Renderer.DrawItemImage(new System.Windows.Forms.ToolStripItemImageRenderEventArgs(e.Graphics, this, draw_image, image_layout_rect));
                }

                this.Owner.Renderer.DrawArrow(new ToolStripArrowRenderEventArgs(e.Graphics, this, new Rectangle_(this.Width - 9, 1, 6, this.Height), Color_.Black, ArrowDirection.Down));

                return;
            }
        }
Esempio n. 3
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);

            // Can't render without an owner
            if (this.Owner == null)
            {
                return;
            }

            // If DropDown.ShowImageMargin is false, we don't display the image
            Image draw_image = this.UseImageMargin ? this.Image : null;

            // Figure out our text color
            Color font_color = this.ForeColor == SystemColors.ControlText ? SystemColors.MenuText : this.ForeColor;

            if ((this.Selected || this.Pressed) && this.IsOnDropDown && font_color == SystemColors.MenuText)
            {
                font_color = SystemColors.HighlightText;
            }

            if (!this.Enabled && this.ForeColor == SystemColors.ControlText)
            {
                font_color = SystemColors.GrayText;
            }

            // Gray stuff out if we're disabled
            draw_image = this.Enabled ? draw_image : ToolStripRenderer.CreateDisabledImage(draw_image);

            // Draw our background
            this.Owner.Renderer.DrawMenuItemBackground(new ToolStripItemRenderEventArgs(e.Graphics, this));

            // Figure out where our text and image go
            Rectangle text_layout_rect;
            Rectangle image_layout_rect;

            this.CalculateTextAndImageRectangles(out text_layout_rect, out image_layout_rect);

            if (this.IsOnDropDown)
            {
                if (!this.UseImageMargin)
                {
                    image_layout_rect = Rectangle.Empty;
                    text_layout_rect  = new Rectangle(8, text_layout_rect.Top, text_layout_rect.Width, text_layout_rect.Height);
                }
                else
                {
                    text_layout_rect = new Rectangle(35, text_layout_rect.Top, text_layout_rect.Width, text_layout_rect.Height);

                    if (image_layout_rect != Rectangle.Empty)
                    {
                        image_layout_rect = new Rectangle(new Point(4, 3), base.GetImageSize());
                    }
                }

                if (this.Checked && this.ShowMargin)
                {
                    this.Owner.Renderer.DrawItemCheck(new ToolStripItemImageRenderEventArgs(e.Graphics, this, new Rectangle(2, 1, 19, 19)));
                }
            }
            if (text_layout_rect != Rectangle.Empty)
            {
                this.Owner.Renderer.DrawItemText(new ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, font_color, this.Font, this.TextAlign));
            }

            string key_string = GetShortcutDisplayString();

            if (!string.IsNullOrEmpty(key_string) && !this.HasDropDownItems)
            {
                int       offset          = 15;
                Size      key_string_size = TextRenderer.MeasureText(key_string, this.Font);
                Rectangle key_string_rect = new Rectangle(this.ContentRectangle.Right - key_string_size.Width - offset, text_layout_rect.Top, key_string_size.Width, text_layout_rect.Height);
                this.Owner.Renderer.DrawItemText(new ToolStripItemTextRenderEventArgs(e.Graphics, this, key_string, key_string_rect, font_color, this.Font, this.TextAlign));
            }

            if (image_layout_rect != Rectangle.Empty)
            {
                this.Owner.Renderer.DrawItemImage(new ToolStripItemImageRenderEventArgs(e.Graphics, this, draw_image, image_layout_rect));
            }

            if (this.IsOnDropDown && this.HasDropDownItems && this.Parent is ToolStripDropDownMenu)
            {
                this.Owner.Renderer.DrawArrow(new ToolStripArrowRenderEventArgs(e.Graphics, this, new Rectangle(this.Bounds.Width - 17, 2, 10, 20), Color.Black, ArrowDirection.Right));
            }

            return;
        }
Esempio n. 4
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (this.Owner != null)
            {
                Color font_color = this.Enabled ? this.ForeColor : SystemColors.GrayText;
                Image draw_image = this.Enabled ? this.Image : ToolStripRenderer.CreateDisabledImage(this.Image);

                this.Owner.Renderer.DrawLabelBackground(new System.Windows.Forms.ToolStripItemRenderEventArgs(e.Graphics, this));

                Rectangle text_layout_rect;
                Rectangle image_layout_rect;

                this.CalculateTextAndImageRectangles(out text_layout_rect, out image_layout_rect);

                if (this.IsOnDropDown)
                {
                    if (this.ShowMargin)
                    {
                        text_layout_rect = new Rectangle(35, text_layout_rect.Top, text_layout_rect.Width, text_layout_rect.Height);
                    }
                    else
                    {
                        text_layout_rect = new Rectangle(7, text_layout_rect.Top, text_layout_rect.Width, text_layout_rect.Height);
                    }
                    if (image_layout_rect != Rectangle.Empty)
                    {
                        image_layout_rect = new Rectangle(new Point(4, 3), base.GetImageSize());
                    }
                }

                if (image_layout_rect != Rectangle.Empty)
                {
                    this.Owner.Renderer.DrawItemImage(new System.Windows.Forms.ToolStripItemImageRenderEventArgs(e.Graphics, this, draw_image, image_layout_rect));
                }
                if (text_layout_rect != Rectangle.Empty)
                {
                    if (this.is_link)
                    {
                        if (this.Pressed)       // Mouse Down
                        {
                            switch (this.link_behavior)
                            {
                            case LinkBehavior.SystemDefault:
                            case LinkBehavior.AlwaysUnderline:
                            case LinkBehavior.HoverUnderline:
                                this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, this.active_link_color, new Font(this.Font, FontStyle.Underline), this.TextAlign));
                                break;

                            case LinkBehavior.NeverUnderline:
                                this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, this.active_link_color, this.Font, this.TextAlign));
                                break;
                            }
                        }
                        else if (this.Selected)         // Hover
                        {
                            switch (this.link_behavior)
                            {
                            case LinkBehavior.SystemDefault:
                            case LinkBehavior.AlwaysUnderline:
                            case LinkBehavior.HoverUnderline:
                                this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, this.link_color, new Font(this.Font, FontStyle.Underline), this.TextAlign));
                                break;

                            case LinkBehavior.NeverUnderline:
                                this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, this.link_color, this.Font, this.TextAlign));
                                break;
                            }
                        }
                        else
                        {
                            if (this.link_visited)      // Normal, Visited
                            {
                                switch (this.link_behavior)
                                {
                                case LinkBehavior.SystemDefault:
                                case LinkBehavior.AlwaysUnderline:
                                    this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, this.visited_link_color, new Font(this.Font, FontStyle.Underline), this.TextAlign));
                                    break;

                                case LinkBehavior.NeverUnderline:
                                case LinkBehavior.HoverUnderline:
                                    this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, this.visited_link_color, this.Font, this.TextAlign));
                                    break;
                                }
                            }
                            else                        // Normal
                            {
                                switch (this.link_behavior)
                                {
                                case LinkBehavior.SystemDefault:
                                case LinkBehavior.AlwaysUnderline:
                                    this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, this.link_color, new Font(this.Font, FontStyle.Underline), this.TextAlign));
                                    break;

                                case LinkBehavior.NeverUnderline:
                                case LinkBehavior.HoverUnderline:
                                    this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, this.link_color, this.Font, this.TextAlign));
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        this.Owner.Renderer.DrawItemText(new System.Windows.Forms.ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, text_layout_rect, font_color, this.Font, this.TextAlign));
                    }
                }
            }

            // call Paint handlers last.
            base.OnPaint(e);
        }