Esempio n. 1
0
        public void InitControls()
        {
            int scrollBarBuffer = System.Windows.Forms.SystemInformation.VerticalScrollBarWidth + 5;
            int swatchesWidth   = (ColorPalettePanel.SWATCH_WIDTH * SwatchesPerRow) + scrollBarBuffer;
            int paletteWidth    = swatchesWidth + (2 * palettePadding);

            this.Width  = paletteWidth;
            this.Height = 300;

            Button narrowPaletteButton = new Button();

            narrowPaletteButton.Text = "<<";
            LayoutHelper.Bottom(this, palettePadding).Left(this, palettePadding).Width(ColorPalettePanel.SWATCH_WIDTH).Height(ColorPalettePanel.SWATCH_WIDTH).Apply(narrowPaletteButton);
            narrowPaletteButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
            narrowPaletteButton.Click += new EventHandler(Form_OnNarrowPalette);
            this.Controls.Add(narrowPaletteButton);

            Button widenPaletteButton = new Button();

            widenPaletteButton.Text = ">>";
            LayoutHelper.Bottom(this, palettePadding).Right(this, palettePadding).Width(ColorPalettePanel.SWATCH_WIDTH).Height(ColorPalettePanel.SWATCH_WIDTH).Apply(widenPaletteButton);
            widenPaletteButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            widenPaletteButton.Click += new EventHandler(Form_OnWidenPalette);
            this.Controls.Add(widenPaletteButton);

            colorPalettePanel = new ColorPalettePanel();
            LayoutHelper.Top(this).MatchLeft(narrowPaletteButton).MatchRight(widenPaletteButton).Above(narrowPaletteButton, palettePadding).Apply(colorPalettePanel);
            colorPalettePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
            this.Controls.Add(colorPalettePanel);
        }
 private void InitStatusPanel()
 {
     statusPanel = new StatusPanel();
     LayoutHelper.Bottom(this).RightOf(palettePanel).Right(this).Height(statusPanel.Height).Apply(statusPanel);
     statusPanel.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
     this.Controls.Add(statusPanel);
 }
Esempio n. 3
0
        private void InitControls(string text)
        {
            int margin = 10;

            Button okButton = new Button();

            okButton.Text = "Ok";
            LayoutHelper.Bottom(this, margin).CenterWidth(this, 50).Height(20).Apply(okButton);
            okButton.Click += new EventHandler(OkButton_OnClick);

            Label label = new Label();

            LayoutHelper.Above(okButton, margin).Left(this, margin).Top(this, margin).Right(this, margin).Apply(label);
            label.Text = text;

            this.Controls.Add(label);
            this.Controls.Add(okButton);
        }
        public void LayoutHelper_CenterWidth()
        {
            //assemble
            Form form = new Form()
            {
                Width  = 300,
                Height = 150,
            };
            int           margin      = 10;
            int           buttonWidth = 50;
            LayoutOptions options     = LayoutHelper.Bottom(form, margin).CenterWidth(form, buttonWidth).Height(20);
            Button        button      = new Button();

            //act
            options.Apply(button);
            //assert
            Assert.AreEqual((form.ClientSize.Width - buttonWidth) / 2, button.Location.X);
        }
Esempio n. 5
0
        private void InitControls()
        {
            int margin       = 10;
            int buttonHeight = 20;
            int buttonWidth  = 150;

            Button okButton = new Button();

            okButton.Text = "Save Projects";
            LayoutHelper.Bottom(this, margin).Left(this, margin).Width(buttonWidth).Height(buttonHeight).Apply(okButton);
            okButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
            okButton.Click += new EventHandler(OkButton_OnClick);
            this.Controls.Add(okButton);

            Button cancelButton = new Button();

            cancelButton.Text = "Cancel";
            LayoutHelper.MatchTop(okButton).Right(this, margin).Width(buttonWidth).Height(buttonHeight).Apply(cancelButton);
            cancelButton.Click += new EventHandler(CancelButton_OnClick);
            cancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            this.Controls.Add(cancelButton);

            Label instructionLabel = new Label();

            instructionLabel.Text = "Some of the projects in this collection have not been saved.\n\nSet the save location for each project.";
            LayoutHelper.Left(this, margin).Right(this, margin).Top(this, margin).Height(40).Apply(instructionLabel);
            instructionLabel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            this.Controls.Add(instructionLabel);

            Panel scrollPanel = new Panel();

            scrollPanel.AutoScroll = true;
            LayoutHelper.Left(this, margin).Right(this, margin).Below(instructionLabel, margin).Above(okButton, margin).Apply(scrollPanel);
            scrollPanel.Anchor = LayoutHelper.AnchorAll;
            this.Controls.Add(scrollPanel);

            int maxThumbnailWidth  = thumbnails.Max(t => t.Width);
            int maxThumbnailHeight = thumbnails.Max(t => t.Height);
            int maxScrollHeight    = 0;

            for (int i = 0; i < thumbnails.Length; i++)
            {
                Bitmap thumbnail = thumbnails[i];

                Panel projectPanel = new Panel();

                PictureBox pictureBox = new PictureBox();
                pictureBox.Image    = thumbnail;
                pictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
                LayoutHelper.Left(projectPanel, margin).Top(projectPanel, margin).Width(maxThumbnailWidth).Height(thumbnail.Height).Apply(pictureBox);
                pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Left;
                projectPanel.Controls.Add(pictureBox);

                Button setFileNameButton = new Button();
                setFileNameButton.TabIndex = i;
                setFileNameButton.Text     = "Set Save Location";
                LayoutHelper.RightOf(pictureBox, margin).MatchTop(pictureBox).Width(buttonWidth).Height(buttonHeight).Apply(setFileNameButton);
                setFileNameButton.Anchor = AnchorStyles.Top | AnchorStyles.Left;
                setFileNameButton.Click += new EventHandler(SetFileNameButton_OnClick);
                projectPanel.Controls.Add(setFileNameButton);

                Label fileNameLabel = new Label();
                fileNameLabel.TabIndex = i;
                fileNameLabel.TabStop  = false;
                fileNameLabel.Text     = "<<no file name>>";
                LayoutHelper.Left(projectPanel, margin).Below(pictureBox, margin).MatchWidth(projectPanel).Height(20).Apply(fileNameLabel);
                fileNameLabel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                projectPanel.Controls.Add(fileNameLabel);

                LayoutHelper.Left(scrollPanel).FloatTop(scrollPanel).MatchWidth(scrollPanel).Height(fileNameLabel.Top + fileNameLabel.Height).Apply(projectPanel);
                projectPanel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                scrollPanel.Controls.Add(projectPanel);
                maxScrollHeight = projectPanel.Top + projectPanel.Height + margin;
            }

            //shorten dialog if it is unnecessarily tall
            int scrollPanelBottom = scrollPanel.Top + maxScrollHeight;

            if (scrollPanelBottom < okButton.Top - margin)
            {
                this.Height -= (okButton.Top - margin - scrollPanelBottom);
            }
        }