ComponentFactory.Krypton.Toolkit.VisualTaskDialog.UpdateFooterSizing C# (CSharp) Method

UpdateFooterSizing() private method

private UpdateFooterSizing ( ) : Size
return System.Drawing.Size
        private Size UpdateFooterSizing()
        {
            // Update size of the footer but applying a sensible maximum
            using (Graphics g = CreateGraphics())
            {
                // Find size of the labels when it has a maximum length of 400
                _footerLabel.UpdateFont();
                Size footerTextSize = g.MeasureString(_footerText, _footerLabel.Font, 200).ToSize();
                Size footerHyperlinkSize = g.MeasureString(_footerHyperlink, _footerLabel.Font, 200).ToSize();

                // Always add on an extra 5 pixels as sometimes the measure size does not draw the last
                // character it contains, this ensures there is always definitely enough space for it all
                footerTextSize.Width += 5;
                footerHyperlinkSize.Width += 5;
                _footerLabel.Size = footerTextSize;
                _linkLabelFooter.Size = footerHyperlinkSize;

                // Find required size of the footer panel
                Size requiredSize = Size.Empty;

                if (!string.IsNullOrEmpty(_footerText))
                {
                    requiredSize.Width += footerTextSize.Width;
                    requiredSize.Height = footerTextSize.Height;
                }

                if (!string.IsNullOrEmpty(_footerHyperlink))
                {
                    requiredSize.Width += footerHyperlinkSize.Width;
                    requiredSize.Height = Math.Max(requiredSize.Height, footerHyperlinkSize.Height);
                }

                if ((_footerIcon != MessageBoxIcon.None) || (_customFooterIcon != null))
                {
                    requiredSize.Width += _iconFooter.Width + BUTTON_GAP;
                    requiredSize.Height = Math.Max(requiredSize.Height, _iconFooter.Size.Height);
                }

                if (requiredSize.Width > 0)
                {
                    requiredSize.Width += BUTTON_GAP * 2;
                    requiredSize.Height += BUTTON_GAP * 2;
                }

                 // Do we have anything to show?
                _panelFooter.Visible = (requiredSize.Width > 0);

                // Position the footer elements
                if (requiredSize.Width > 0)
                {
                    _panelFooter.Size = requiredSize;
                    int offset = BUTTON_GAP;

                    if ((_footerIcon != MessageBoxIcon.None) || (_customFooterIcon != null))
                    {
                        _iconFooter.Location = new Point(offset, (requiredSize.Height - _iconFooter.Height) / 2);
                        offset += _iconFooter.Width + BUTTON_GAP / 2;
                    }

                    if (!string.IsNullOrEmpty(_footerText))
                    {
                        _footerLabel.Location = new Point(offset, (requiredSize.Height - footerTextSize.Height) / 2);
                        offset += _footerLabel.Width - 8;
                    }

                    if (!string.IsNullOrEmpty(_footerHyperlink))
                    {
                        if (!string.IsNullOrEmpty(_footerText))
                            _linkLabelFooter.Location = new Point(offset, _footerLabel.Location.Y -  1);
                        else
                            _linkLabelFooter.Location = new Point(offset, (requiredSize.Height - footerHyperlinkSize.Height) / 2);

                        offset += _footerLabel.Width;
                    }
                }

                return requiredSize;
            }
        }