コード例 #1
0
        public static void PerformAutoLayout(
            System.Windows.Forms.ButtonBase button,
            AutoSizeStrategy autoSizeLayoutStrategy,
            EdgeSnapOptions edgeSnapOptions)
        {
            Control container = button.Parent;

            // Make sure no extra, not-yet-defined options were snuck in
            EdgeSnapOptions allEdgeSnapOptions = EdgeSnapOptions.SnapLeftEdgeToContainerLeftEdge | EdgeSnapOptions.SnapRightEdgeToContainerRightEdge;

            if (0 != (edgeSnapOptions & ~allEdgeSnapOptions))
            {
                throw new InvalidEnumArgumentException("edgeSnapOptions");
            }

            if ((edgeSnapOptions & EdgeSnapOptions.SnapLeftEdgeToContainerLeftEdge) != 0)
            {
                int oldLeft = button.Left;
                button.Left   = 0;
                button.Width += oldLeft;
            }

            if (container != null && (edgeSnapOptions & EdgeSnapOptions.SnapRightEdgeToContainerRightEdge) != 0)
            {
                button.Width = container.Width - button.Left;
            }

            switch (autoSizeLayoutStrategy)
            {
            case AutoSizeStrategy.AutoHeightAndExpandWidthToContent:
                button.Size = button.GetPreferredSize(new Size(0, 0));
                break;

            case AutoSizeStrategy.ExpandHeightToContentAndKeepWidth:
                if (button.Width != 0)
                {
                    Size preferredSizeP = button.GetPreferredSize(new Size(button.Width, 1));
                    Size preferredSize  = new Size((preferredSizeP.Width * 11) / 10, preferredSizeP.Height);    // add 10% padding

                    int lineHeight   = preferredSize.Height;
                    int overageScale = (preferredSize.Width + (button.Width - 1)) / button.Width;
                    button.Height = lineHeight * overageScale;
                }
                break;

            case AutoSizeStrategy.None:
                break;

            default:
                throw new InvalidEnumArgumentException("autoSizeLayoutStrategy");
            }
        }
コード例 #2
0
ファイル: LayoutUtility.cs プロジェクト: metadeta96/openpdn
        public static void PerformAutoLayout(
            System.Windows.Forms.ButtonBase button,
            AutoSizeStrategy autoSizeLayoutStrategy,
            EdgeSnapOptions edgeSnapOptions)
        {
            Control container = button.Parent;

            // Make sure no extra, not-yet-defined options were snuck in
            EdgeSnapOptions allEdgeSnapOptions = EdgeSnapOptions.SnapLeftEdgeToContainerLeftEdge | EdgeSnapOptions.SnapRightEdgeToContainerRightEdge;
            if (0 != (edgeSnapOptions & ~allEdgeSnapOptions))
            {
                throw new InvalidEnumArgumentException("edgeSnapOptions");
            }

            if ((edgeSnapOptions & EdgeSnapOptions.SnapLeftEdgeToContainerLeftEdge) != 0)
            {
                int oldLeft = button.Left;
                button.Left = 0;
                button.Width += oldLeft;
            }

            if (container != null && (edgeSnapOptions & EdgeSnapOptions.SnapRightEdgeToContainerRightEdge) != 0)
            {
                button.Width = container.Width - button.Left;
            }

            switch (autoSizeLayoutStrategy)
            {
                case AutoSizeStrategy.AutoHeightAndExpandWidthToContent:
                    button.Size = button.GetPreferredSize(new Size(0, 0));
                    break;

                case AutoSizeStrategy.ExpandHeightToContentAndKeepWidth:
                    if (button.Width != 0)
                    {
                        Size preferredSizeP = button.GetPreferredSize(new Size(button.Width, 1));
                        Size preferredSize = new Size((preferredSizeP.Width * 11) / 10, preferredSizeP.Height); // add 10% padding

                        int lineHeight = preferredSize.Height;
                        int overageScale = (preferredSize.Width + (button.Width - 1)) / button.Width;
                        button.Height = lineHeight * overageScale;
                    }
                    break;

                case AutoSizeStrategy.None:
                    break;

                default:
                    throw new InvalidEnumArgumentException("autoSizeLayoutStrategy");
            }
        }
コード例 #3
0
        protected override void OnLayout(LayoutEventArgs e)
        {
            int vMargin = UI.ScaleHeight(4);
            int hInset  = UI.ScaleWidth(16);

            AutoSizeStrategy autoSizeStrategy = AutoSizeStrategy.ExpandHeightToContentAndKeepWidth;
            EdgeSnapOptions  edgeSnapOptions  =
                EdgeSnapOptions.SnapLeftEdgeToContainerLeftEdge |
                EdgeSnapOptions.SnapRightEdgeToContainerRightEdge;

            this.fileFormatList.Location = new Point(0, 0);
            this.fileFormatList.Width    = ClientSize.Width;
            this.fileFormatList.PerformLayout();

            this.compressorTypeLabel.Location = new Point(0, this.fileFormatList.Bottom + vMargin * 2);
            this.compressorTypeLabel.Size     = this.compressorTypeLabel.GetPreferredSize(new Size(ClientSize.Width - this.compressorTypeLabel.Left, 1));
            this.compressorTypeLabel.PerformLayout();

            this.compressorTypePanel.SuspendLayout();
            this.compressorTypePanel.Location = new Point(hInset, this.compressorTypeLabel.Bottom + vMargin);
            this.compressorTypePanel.Width    = ClientSize.Width - this.compressorTypePanel.Left;
            this.rangeFit.Location            = new Point(0, 0);
            LayoutUtility.PerformAutoLayout(this.rangeFit, autoSizeStrategy, edgeSnapOptions);
            this.clusterFit.Location = new Point(0, this.rangeFit.Bottom + vMargin);
            LayoutUtility.PerformAutoLayout(this.clusterFit, autoSizeStrategy, edgeSnapOptions);
            this.iterativeFit.Location = new Point(0, this.clusterFit.Bottom + vMargin);
            LayoutUtility.PerformAutoLayout(this.iterativeFit, autoSizeStrategy, edgeSnapOptions);
            this.compressorTypePanel.Height = this.iterativeFit.Bottom;
            this.compressorTypePanel.ResumeLayout(true);

            this.errorMetricLabel.Location = new Point(0, this.compressorTypePanel.Bottom + vMargin * 2);
            this.errorMetricLabel.Size     = this.errorMetricLabel.GetPreferredSize(new Size(ClientSize.Width - this.errorMetricLabel.Left, 1));
            this.errorMetricLabel.PerformLayout();

            this.errorMetricPanel.SuspendLayout();
            this.errorMetricPanel.Location = new Point(hInset, this.errorMetricLabel.Bottom + vMargin);
            this.errorMetricPanel.Width    = ClientSize.Width - this.errorMetricPanel.Left;
            this.uniformMetric.Location    = new Point(0, 0);
            LayoutUtility.PerformAutoLayout(this.uniformMetric, autoSizeStrategy, edgeSnapOptions);
            this.perceptualMetric.Location = new Point(0, this.uniformMetric.Bottom + vMargin);
            LayoutUtility.PerformAutoLayout(this.perceptualMetric, autoSizeStrategy, edgeSnapOptions);
            this.errorMetricPanel.Height = this.perceptualMetric.Bottom;
            this.errorMetricPanel.ResumeLayout(true);

            this.additionalOptionsLabel.Location = new Point(0, this.errorMetricPanel.Bottom + vMargin * 2);
            this.additionalOptionsLabel.Size     = this.additionalOptionsLabel.GetPreferredSize(new Size(ClientSize.Width - this.additionalOptionsLabel.Left, 1));
            this.additionalOptionsLabel.PerformLayout();

            this.additionalOptionsPanel.SuspendLayout();
            this.additionalOptionsPanel.Location = new Point(hInset, this.additionalOptionsLabel.Bottom + vMargin);
            this.additionalOptionsPanel.Width    = ClientSize.Width - this.additionalOptionsPanel.Left;
            this.weightColourByAlpha.Location    = new Point(0, 0);
            LayoutUtility.PerformAutoLayout(this.weightColourByAlpha, autoSizeStrategy, edgeSnapOptions);
            this.generateMipMaps.Location = new Point(0, this.weightColourByAlpha.Bottom + vMargin);
            LayoutUtility.PerformAutoLayout(this.generateMipMaps, autoSizeStrategy, edgeSnapOptions);
            this.additionalOptionsPanel.Height = this.generateMipMaps.Bottom;
            this.additionalOptionsPanel.ResumeLayout(true);

            this.ClientSize = new Size(ClientSize.Width, this.additionalOptionsPanel.Bottom);
            base.OnLayout(e);
        }