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); }
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); }