public override Size GetPreferredSize(Size constrainingSize)
 {
     constrainingSize         = Renderer.GetPreferredSize(constrainingSize);
     constrainingSize.Width  += Padding.Horizontal;
     constrainingSize.Height += Padding.Vertical;
     return(constrainingSize);
 }
Example #2
0
 public override Size GetPreferredSize(Size proposedSize)
 {
     proposedSize         = Renderer.GetPreferredSize(proposedSize);
     proposedSize.Width  += Padding.Horizontal;
     proposedSize.Height += Padding.Vertical;
     return(proposedSize);
 }
        protected override void OnPaint(PaintEventArgs e)
        {
            using (e)
            {
                switch (DisplayStyle)
                {
                case ToolStripItemDisplayStyle.Image:
                case ToolStripItemDisplayStyle.ImageAndText:
                    Rectangle ThrobberBounds = new Rectangle(Padding.Left, Padding.Top, Width - Padding.Horizontal, Height - Padding.Vertical);
                    Rectangle TextBounds;

                    if (DisplayStyle == ToolStripItemDisplayStyle.ImageAndText)
                    {
                        Size ThrobberSize = Renderer.GetPreferredSize(Size);
                        TextBounds = ThrobberBounds;

                        switch (TextImageRelation)
                        {
                        case TextImageRelation.ImageAboveText:
                            ThrobberBounds.Height = ThrobberSize.Height;
                            TextBounds.Y         += ThrobberSize.Height;
                            TextBounds.Height    -= ThrobberSize.Height;
                            break;

                        case TextImageRelation.TextAboveImage:
                            ThrobberBounds.Y      = ThrobberBounds.Bottom - ThrobberSize.Height;
                            ThrobberBounds.Height = ThrobberSize.Height;
                            TextBounds.Height    -= ThrobberSize.Height;
                            break;

                        case TextImageRelation.ImageBeforeText:
                            ThrobberBounds.Width = ThrobberSize.Width;
                            TextBounds.X        += ThrobberSize.Width;
                            TextBounds.Width    -= ThrobberSize.Width;
                            break;

                        case TextImageRelation.TextBeforeImage:
                            ThrobberBounds.X     = ThrobberBounds.Right - ThrobberSize.Width;
                            ThrobberBounds.Width = ThrobberSize.Width;
                            TextBounds.Width    -= ThrobberSize.Width;
                            break;
                        }
                    }
                    else
                    {
                        TextBounds = Rectangle.Empty;
                    }

                    ToolStripItemRenderEventArgs ItemArgs = new ToolStripItemRenderEventArgs(e.Graphics, this);
                    Parent.Renderer.DrawButtonBackground(ItemArgs);

                    ThrobberRenderEventArgs RenderArgs = new ThrobberRenderEventArgs(e.Graphics, ThrobberBounds, Position, Enabled);
                    Renderer.DrawThrobber(RenderArgs);
                    Position = RenderArgs.Position;

                    if (!TextBounds.IsEmpty)
                    {
                        ToolStripItemTextRenderEventArgs TextArgs = new ToolStripItemTextRenderEventArgs(e.Graphics, this, Text,
                                                                                                         TextBounds, ForeColor, Font, TextAlign);
                        Parent.Renderer.DrawItemText(TextArgs);
                    }

                    break;

                default:
                    base.OnPaint(e);
                    break;
                }
            }
        }