Пример #1
0
        private void DisplayPalette()
        {
            int maxCols       = 32;
            int rows          = (palette.Keys.Count / maxCols) + 1;
            int actualCols    = rows == 1 ? Math.Min(palette.Keys.Count, maxCols) : maxCols;
            int paletteOffset = 0;

            Panel[,] output = new Panel[rows, actualCols];

            int tileSizeX = pnlPalette.Width / actualCols;
            int tileSizeY = pnlPalette.Height / rows;

            try
            {
                for (int x = 0; x < actualCols; x++)
                {
                    for (int y = 0; y < rows; y++)
                    {
                        if (paletteOffset < palette.Keys.Count)
                        {
                            int pX = tileSizeX * x + pnlPalette.Location.X;
                            int pY = tileSizeY * y + pnlPalette.Location.Y;
                            Console.WriteLine("C:{0} @ ({1},{2})", palette.Values.ElementAt(paletteOffset), pX, pY);

                            var newPanel = new CustomPanel(x, y, new ColorTuple(palette.Keys.ElementAt(paletteOffset), palette.Values.ElementAt(paletteOffset)))
                            {
                                Size      = new Size(tileSizeX, tileSizeY),
                                Location  = new Point(pX, pY),
                                BackColor = palette.Values.ElementAt(paletteOffset++)
                            };

                            Controls.Add(newPanel);
                            newPanel.Click += NewPanel_Click;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (paletteOffset >= palette.Keys.Count)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
            }

            pnlPalette.Visible = false;
        }
Пример #2
0
 private void NewPanel_Click(object sender, EventArgs e)
 {
     CustomPanel src = (CustomPanel)sender;
 }