private void Form_OnAdd(object sender, EventArgs e)
 {
     using (NewColorDialog dialog = new NewColorDialog())
     {
         dialog.StartPosition = FormStartPosition.Manual;
         dialog.Location      = new Point(this.Location.X + 30, this.Location.Y + 30);
         if (dialog.ShowDialog() == DialogResult.OK)
         {
             AddColorToPaletteWithHistory(dialog.Color);
         }
     }
 }
        private void Color_OnAddBasedOn(object sender, EventArgs e)
        {
            Control control  = (sender as MenuItem).GetContextMenu().SourceControl;
            Color   oldColor = control.BackColor;

            using (NewColorDialog dialog = new NewColorDialog(oldColor))
            {
                dialog.StartPosition = FormStartPosition.Manual;
                dialog.Location      = new Point(this.Location.X + 30, this.Location.Y + 30);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    Color newColor = dialog.Color;
                    int   index    = colorPalette.Count;
                    AddColorToPalette(newColor, index);
                    history.Add(new AddPaletteColorAction(newColor, index));
                }
            }
        }
        private void Color_OnEdit(object sender, EventArgs e)
        {
            Control control  = (sender as MenuItem).GetContextMenu().SourceControl;
            Color   oldColor = control.BackColor;

            using (NewColorDialog dialog = new NewColorDialog(oldColor))
            {
                dialog.StartPosition = FormStartPosition.Manual;
                dialog.Location      = new Point(this.Location.X + 30, this.Location.Y + 30);
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    Color newColor = dialog.Color;
                    ReplaceColorInPalette(control.TabIndex, newColor);

                    ReplacePaletteColorAction action = new ReplacePaletteColorAction(control.TabIndex, oldColor, newColor);
                    action.ReplaceColor += new PaletteEventHandler(Palette_OnReplaceColor);
                    history.Add(action);
                }
            }
        }