Ejemplo n.º 1
0
        private void Init()
        {
            int margin = 10;

            this.Width           = (HuePanel.UNIT + margin + margin /*why second margin needed?*/) * 2;
            this.Height          = 500 + margin;
            this.Text            = "New Color";
            this.FormBorderStyle = FormBorderStyle.FixedSingle;             //disable resize
            this.MinimizeBox     = false;
            this.MaximizeBox     = false;

            huePanel               = new HuePanel(Color);
            huePanel.Location      = new Point(margin, margin);
            huePanel.ColorChanged += new EventHandler(Hue_OnChange);
            this.Controls.Add(huePanel);

            saturationValuePanel               = new SaturationValuePanel(Color);
            saturationValuePanel.Location      = new Point(margin, huePanel.Location.Y + huePanel.Height + margin);
            saturationValuePanel.ColorChanged += new EventHandler(SaturationValue_OnChange);
            this.Controls.Add(saturationValuePanel);

            Button okButton = new Button();

            LayoutHelper.RightOf(saturationValuePanel, margin).Bottom(this, margin).Width(100).Height(25).Apply(okButton);
            okButton.Text   = "Ok";
            okButton.Click += new EventHandler(Ok_OnClick);
            this.Controls.Add(okButton);

            Button cancelButton = new Button();

            LayoutHelper.RightOf(okButton, margin).Bottom(this, margin).Width(100).Height(25).Apply(cancelButton);
            cancelButton.Text   = "Cancel";
            cancelButton.Click += new EventHandler(Cancel_OnClick);
            this.Controls.Add(cancelButton);

            colorDataPanel = new ColorDataPanel(readOnly: false);
            LayoutHelper.Above(okButton, margin).Right(this, margin).Below(huePanel).Width(150).Apply(colorDataPanel);
            colorDataPanel.Anchor        = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
            colorDataPanel.ColorChanged += new ColorEventHandler(ColorData_OnChange);
            this.Controls.Add(colorDataPanel);

            selectedColorPanel = new Panel();
            LayoutHelper.RightOf(saturationValuePanel, margin).Below(huePanel, margin).LeftOf(colorDataPanel).Above(okButton, margin).Apply(selectedColorPanel);
            UpdateSelectedColor();
            this.Controls.Add(selectedColorPanel);
        }
Ejemplo n.º 2
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);
        }