コード例 #1
0
        internal MainWindow()
        {
            // Set Size and center the window
            Size = new Size(1200 + BorderInformation, 600);
            CenterToScreen();

            // Create a new menu strip and assign it to our MainMenuStrip property
            MenuStrip mainMenu = new MenuStrip();

            MainMenuStrip = mainMenu;
            this.Controls.Add(mainMenu);

            // Create a new GridBox control and resize it
            GridBox gridBox = new GridBox();

            gridBox.ParentWindow = this;
            gridBox.Location     = new Point((15 * 3) + (5 * 3) + 20, MainMenuStrip.Height);
            this.Controls.Add(gridBox);
            gridBox.ResizeGridBox();

            // Assign an event handler to a ResizeEnd event
            ResizeEnd += new EventHandler(HandleResizeEnd);

            // Now we actually populate the menu
            this.PopulateMenubar();

            // Draw the color boxes (for color selection)
            Label colorsLabel = new Label();

            colorsLabel.Location = new Point(5, MainMenuStrip.Height + 1);
            colorsLabel.Text     = "Colors:";
            this.Controls.Add(colorsLabel);

            int y = MainMenuStrip.Height + colorsLabel.Height + 3, x = 5; // x,y topleft point. Pixels.

            for (int i = 1; i <= PredefinedColors.Length; i++)
            {
                // i == 1 initially because 0 % N is 0,
                // which causes a logic problem later on.
                // We'll just always pull the color at i-1 instead of i.
                Color    color    = ColorTranslator.FromHtml(PredefinedColors[i - 1]);
                ColorBox colorBox = new ColorBox(this);
                colorBox.Location  = new Point(x, y);
                colorBox.Size      = new Size(15, 15);
                colorBox.BackColor = color;
                this.Controls.Add(colorBox);
                x += colorBox.Width + 10;
                if (i % 3 == 0)
                {
                    /* On every 3 ColorBoxes drawn we move downwards by the ColorBox's height plus 10 pixels.
                     * We also have to reset x to its original position. */
                    x  = 5;
                    y += colorBox.Height + 10;
                }
                colorBox.Invalidate();
            }
            // Now the big ColorBox which shows the currently selected color.
            y += 10;
            Label selected = new Label();

            selected.Text     = "Selected:";
            selected.Location = new Point(5, y);
            this.Controls.Add(selected);

            ColorBox bigBox = new ColorBox(this);

            bigBox.Location  = new Point(5, y + 25);
            bigBox.Size      = new Size((15 * 3) + (5 * 3) + 5, 50);
            bigBox.BackColor = gridBox.SelectedColor; // Should be white.
            bigBox.Name      = "BigBox";              // Required for updating the BackColor of the box
            this.Controls.Add(bigBox);
            bigBox.Invalidate();
        }