示例#1
0
        private void Init(bool readOnly)
        {
            int margin        = 10;
            int controlHeight = 25;

            //todo: there must be a far more succint way of saying this in the LayoutHelper

            Label hexadecimalHeader = new Label();

            LayoutHelper.Left(this, margin).Top(this, margin).Width(this.Width).Height(controlHeight).Apply(hexadecimalHeader);
            hexadecimalHeader.Text = "Hexadecimal";
            this.Controls.Add(hexadecimalHeader);

            hexadecimalData      = GetTextBox(readOnly);
            hexadecimalData.Name = NAME_HEXADECIMAL;
            LayoutHelper.Left(this, margin * 2).Below(hexadecimalHeader).Width(this.Width - (margin * 2)).Height(controlHeight).Apply(hexadecimalData);
            hexadecimalData.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            this.Controls.Add(hexadecimalData);

            Label rgbHeader = new Label();

            LayoutHelper.MatchLeft(hexadecimalHeader).Below(hexadecimalData, margin).Width(this.Width).Height(controlHeight).Apply(rgbHeader);
            rgbHeader.Text = "Red, Green, Blue";
            this.Controls.Add(rgbHeader);

            rgbData      = GetTextBox(readOnly);
            rgbData.Name = NAME_RGB;
            LayoutHelper.Left(this, margin * 2).Below(rgbHeader).Width(this.Width - (margin * 2)).Height(controlHeight).Apply(rgbData);
            rgbData.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            this.Controls.Add(rgbData);

            Label hsvHeader = new Label();

            LayoutHelper.MatchLeft(rgbHeader).Below(rgbData, margin).Width(this.Width).Height(controlHeight).Apply(hsvHeader);
            hsvHeader.Text = "Hue, Saturation, Value";
            this.Controls.Add(hsvHeader);

            hsvData      = GetTextBox(readOnly);
            hsvData.Name = NAME_HSV;
            LayoutHelper.Left(this, margin * 2).Below(hsvHeader).Width(this.Width - (margin * 2)).Height(controlHeight).Apply(hsvData);
            hsvData.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            this.Controls.Add(hsvData);
        }
        private void InitControls()
        {
            int margin = 10;

            ToolStrip toolStrip = new ToolStrip();

            toolStrip.Dock = DockStyle.Top;
            toolStrip.Items.Add("Undo", IconManager.UNDO, Form_OnUndo);
            toolStrip.Items.Add("Redo", IconManager.REDO, Form_OnRedo);
            toolStrip.Items.Add(new ToolStripSeparator());
            copyToolStripItem             = toolStrip.Items.Add("Copy", IconManager.DROPPER, Form_OnCopy);
            copyToolStripItem.ToolTipText = "Copy color from the screen to the palette.";
            this.Controls.Add(toolStrip);

            Button addButton = new Button();

            LayoutHelper.Bottom(this, margin).Left(this, margin).Height(25).Width(80).Apply(addButton);
            addButton.Text   = "New Color";
            addButton.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            addButton.Click += new EventHandler(Form_OnAdd);
            this.Controls.Add(addButton);

            ContextMenu colorContextMenu = new ContextMenu();

            colorContextMenu.MenuItems.Add("Edit", Color_OnEdit);
            colorContextMenu.MenuItems.Add("Add New Based on This", Color_OnAddBasedOn);
            colorContextMenu.MenuItems.Add("Delete", Color_OnDelete);

            colorDataPanel = new ColorDataPanel(readOnly: true);
            LayoutHelper.Above(addButton, margin).Right(this, margin).Below(toolStrip).Width(150).Apply(colorDataPanel);
            colorDataPanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
            this.Controls.Add(colorDataPanel);

            colorPalettePanel = new ColorPalettePanel(colorPalette, colorContextMenu);
            colorPalettePanel.ColorChanged += new EventHandler(Color_OnSelect);
            LayoutHelper.Left(this, margin).Below(toolStrip).LeftOf(colorDataPanel).Above(addButton, margin).Apply(colorPalettePanel);
            colorPalettePanel.Anchor = LayoutHelper.AnchorAll;
            UpdateColorData();
            this.Controls.Add(colorPalettePanel);

            Button okButton = new Button();

            LayoutHelper.Bottom(this, margin).MatchRight(colorPalettePanel, margin).Height(25).Width(80).Apply(okButton);
            okButton.Text   = "Done";
            okButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            okButton.Click += new EventHandler(Form_OnDone);
            this.Controls.Add(okButton);

            Button saveAsButton = new Button();

            LayoutHelper.Bottom(this, margin).LeftOf(okButton, margin * 3).Height(25).Width(80).Apply(saveAsButton);
            saveAsButton.Text   = "Save As";
            saveAsButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            saveAsButton.Click += new EventHandler(Form_OnSaveAs);
            this.Controls.Add(saveAsButton);

            Button saveButton = new Button();

            LayoutHelper.Bottom(this, margin).LeftOf(saveAsButton, margin).Height(25).Width(80).Apply(saveButton);
            saveButton.Text   = "Save";
            saveButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            saveButton.Click += new EventHandler(Form_OnSave);
            this.Controls.Add(saveButton);
        }