private T CreateButton <T>(ref ButtonRect btnRect, int tabIndex, string text, MouseEventHandler clickFunc, int colorIndex = -1) where T : Control, new() { Control button = new T() { Location = new Point(btnRect.x, btnRect.y), Size = new Size(btnRect.width, btnRect.height), TabIndex = tabIndex, Text = text, }; // Only set color info when button is a color button (ignoring palette scroll buttons) if (typeof(T) == typeof(ColorButton)) { ((ColorButton)button).Text = null; ((ColorButton)button).Color = ColorsArray.GetColorFromPalette(PaletteIndex, colorIndex); } button.MouseClick += clickFunc; Controls.Add(button); btnRect.x += btnRect.width + btnRect.xSpacing; return((T)button); }
private void SwitchToPalette(int paletteIndex) { if (paletteIndex >= ColorsArray.PALETTE_COUNT || paletteIndex < 0) { throw new IndexOutOfRangeException("paletteIndex out of range"); } this.PaletteIndex = paletteIndex; for (int i = 0; i < ColorsArray.COLORS_PER_PALETTE; i++) { colorToggles[i].Color = ColorsArray.GetColorFromPalette(this.PaletteIndex, i); } }