Пример #1
0
        /// <summary>
        /// Organize controls in form.
        /// </summary>
        private void NormalModeFormView()
        {
            // Suspends new controls from appearing in form until resume command.
            SuspendLayout();

            OrganizePanel();

            // Set width.
            this.Width = 429;

            ListOfServerProperties listServers = ListOfServerProperties.Instance;

            // Set server's image logo size and location.
            pictureBox_ServerImageLogo.Size     = SERVER_IMAGE_LOGO_SIZE;
            pictureBox_ServerImageLogo.Location = new Point((this.ClientRectangle.Width / 2) -
                                                            (pictureBox_ServerImageLogo.Width / 2), Y_LOCATION_SERVER_IMAGE_LOGO);

            int panelLocationX = (this.ClientRectangle.Width / 2) - (panel.Width / 2);

            // Update form if the server allows URL uploading.
            if (!listServers.HasURLUpload((int)_siteToUpload))
            {
                // URL isn't allowed.

                // Disable radio buttons.
                radioButton_Url.Visible   = false;
                radioButton_Image.Visible = false;
                radioButton_Image.Checked = true;

                // Set panel location.
                panel.Location = new Point(panelLocationX,
                                           Y_LOCATION_SERVER_IMAGE_LOGO + SERVER_IMAGE_LOGO_SIZE.Height +
                                           VERTICAL_DISTANCE_BETWEEN_RADIO_BUTTONS_TO_PANEL);
            }
            else
            {
                // URL is allowed.

                radioButton_Image.Visible = true;
                radioButton_Url.Visible   = true;

                // Calculate size of text in image radioButton.
                Size textSize = TextRenderer.MeasureText(radioButton_Image.Text, radioButton_Image.Font);

                // Set radio buttons location.
                radioButton_Image.Location = new Point(panelLocationX,
                                                       Y_LOCATION_SERVER_IMAGE_LOGO + SERVER_IMAGE_LOGO_SIZE.Height +
                                                       VERTICAL_DISTANCE_BETWEEN_LOGO_TO_RADIO_BUTTONS);
                radioButton_Url.Location = new Point(panelLocationX + radioButton_Image.Width,
                                                     Y_LOCATION_SERVER_IMAGE_LOGO + SERVER_IMAGE_LOGO_SIZE.Height +
                                                     VERTICAL_DISTANCE_BETWEEN_LOGO_TO_RADIO_BUTTONS);

                // Set panel location.
                panel.Location = new Point(panelLocationX,
                                           radioButton_Image.Location.Y + radioButton_Image.Height +
                                           VERTICAL_DISTANCE_BETWEEN_RADIO_BUTTONS_TO_PANEL);
            }

            // Set upload button's location.
            button_Upload.Location = new Point(
                (ClientRectangle.Width / 2) - (button_Upload.Width / 2),
                panel.Location.Y + panel.Height +
                VERTICAL_DISTANCE_OF_UPLOAD_BUTTON_FROM_PANEL);

            // Set switch server button's location.
            button_SwitchServer.Location = new Point(SWITCH_SERVER_BUTTON_X_LOCATION,
                                                     button_Upload.Location.Y + button_Upload.Height +
                                                     VERTICAL_BLANK_DISTANCE_UNTIL_CHANGE_SERVER_BUTTON);

            // Set credit label (made by supermath) his location.
            label_creditToSuperMath.Location = new Point(this.ClientRectangle.Width - label_creditToSuperMath.Width -
                                                         HORIZONAL_DISTANCE_FROM_CREDIT_LABEL_TO_BORDER,
                                                         button_Upload.Location.Y + button_Upload.Height +
                                                         VERTICAL_BLANK_DISTANCE_UNTIL_CREDIT_LABEL);

            // Set height of the form.
            this.Height = button_SwitchServer.Location.Y + button_SwitchServer.Height + VERTICAL_DISTANCE_FROM_SWITCH_BUTTON_TO_BOTTOM_OF_THE_FORM;

            // Update all form's controls changes.
            ResumeLayout();
        }
Пример #2
0
        /// <summary>
        /// When the form is load, this method is called.
        /// This method draw all the buttons of the servers.
        /// </summary>
        /// <param name="sender"> The form. </param>
        /// <param name="e"> Useful parameters. </param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Consts for ordering the form.
            const int Y_LOCATION_OF_UPDATE_BUTTON = 6;

            const int NUMBER_OF_BUTTON_COLUMNS     = 3;
            const int HEIGHT_OF_BUTTON             = 75;
            const int WIDTH_OF_BUTTON              = 140;
            const int HEIGHT_SPACE_BETWEEN_BUTTONS = 23;
            const int WIDTH_SPACE_BETWEEN_BUTTONS  = 30;
            const int WIDTH_OF_FORM_UNTIL_PANEL    = 30;
            const int WIDTH_OF_FORM_AFTER_PANEL    = 20;
            const int VERTICAL_DISTANCE_FROM_UPDATE_BUTTON_TO_PANEL = 15;
            const int MAX_NUMBER_OF_ROWS_IN_PANEL = 4;

            const int HORIZONAL_DISTANCE_OF_CREDIT_LABEL_FROM_DOWN_RIGHT_FORM_POINT = 10;
            const int VERTICAL_DISTANCE_OF_CREDIT_LABEL_FROM_DOWN_RIGHT_PANEL       = 5;
            const int VERTICAL_DISTANCE_AFTER_CREDIT_LABEL = 50;

            ListOfServerProperties listServers = ListOfServerProperties.Instance;

            int RealNumberOfRows = (int)Math.Ceiling(
                ((double)listServers.NumberOfServers / NUMBER_OF_BUTTON_COLUMNS));
            int NumberOfRows = (RealNumberOfRows > MAX_NUMBER_OF_ROWS_IN_PANEL) ?
                               MAX_NUMBER_OF_ROWS_IN_PANEL : RealNumberOfRows;

            // Panel with buttons.

            const int X_ADDITIONAL_SIZE_FOR_PANEL_UNTIL_FIRST_BUTTON = 10;
            const int X_ADDITIONAL_SIZE_FOR_PANEL_AFTER_LAST_BUTTON  = 30; // Must be at least double than the X_ADDITIONAL_SIZE_FOR_PANEL_UNTIL_FIRST_BUTTON.
            const int Y_ADDITIONAL_SIZE_FOR_PANEL_UNTIL_FIRST_BUTTON = 10;
            const int Y_ADDITIONAL_SIZE_FOR_PANEL_AFTER_LAST_BUTTON  = 10;

            int startOfPanelX = WIDTH_OF_FORM_UNTIL_PANEL -
                                X_ADDITIONAL_SIZE_FOR_PANEL_UNTIL_FIRST_BUTTON;
            int StartOfPanelY = Y_LOCATION_OF_UPDATE_BUTTON
                                + pictureBox_UpdateButton.Height +
                                VERTICAL_DISTANCE_FROM_UPDATE_BUTTON_TO_PANEL -
                                Y_ADDITIONAL_SIZE_FOR_PANEL_UNTIL_FIRST_BUTTON;
            int WidthOfPanel = X_ADDITIONAL_SIZE_FOR_PANEL_UNTIL_FIRST_BUTTON +
                               ((NUMBER_OF_BUTTON_COLUMNS - 1) *
                                WIDTH_SPACE_BETWEEN_BUTTONS) + (NUMBER_OF_BUTTON_COLUMNS * WIDTH_OF_BUTTON)
                               + X_ADDITIONAL_SIZE_FOR_PANEL_AFTER_LAST_BUTTON;
            int HeightOfPanel = Y_ADDITIONAL_SIZE_FOR_PANEL_UNTIL_FIRST_BUTTON +
                                ((NumberOfRows - 1) * HEIGHT_SPACE_BETWEEN_BUTTONS) +
                                (NumberOfRows * HEIGHT_OF_BUTTON) +
                                Y_ADDITIONAL_SIZE_FOR_PANEL_AFTER_LAST_BUTTON;

            // Create the panel.
            Panel panel = new Panel();

            panel.Location    = new Point(startOfPanelX, StartOfPanelY);
            panel.Size        = new Size(WidthOfPanel, HeightOfPanel);
            panel.BorderStyle = BorderStyle.FixedSingle;
            panel.AutoScroll  = true;

            this.Controls.Add(panel);

            for (int i = 0; i < listServers.NumberOfServers; i++)
            {
                // Saves the current column.
                int column = i % NUMBER_OF_BUTTON_COLUMNS;

                // Saves the current row.
                int row = i / NUMBER_OF_BUTTON_COLUMNS;

                // draw all buttons
                Button but = new Button();
                but.Size     = new Size(WIDTH_OF_BUTTON, HEIGHT_OF_BUTTON);
                but.Location = new Point(X_ADDITIONAL_SIZE_FOR_PANEL_UNTIL_FIRST_BUTTON
                                         + column * (WIDTH_OF_BUTTON + WIDTH_SPACE_BETWEEN_BUTTONS),
                                         Y_ADDITIONAL_SIZE_FOR_PANEL_UNTIL_FIRST_BUTTON + row *
                                         (HEIGHT_OF_BUTTON + HEIGHT_SPACE_BETWEEN_BUTTONS));

                but.BackgroundImage         = listServers.GetBitmapButton(i);
                but.BackgroundImageLayout   = ImageLayout.Stretch;
                but.UseVisualStyleBackColor = true;
                but.TabIndex = i;
                but.Tag      = i; // important: this is according the ENUM
                but.Click   += new System.EventHandler(this.button_Click);

                // Set a tool tip for button.
                toolTip.SetToolTip(but, listServers.GetURL(i));

                // Adds button to form.
                panel.Controls.Add(but);

                // Set the minimum size of the form to its current size.
                this.MinimumSize = new Size(this.Width, this.Height);
            }

            // Set form width.
            this.Width = panel.Width +
                         WIDTH_OF_FORM_UNTIL_PANEL + WIDTH_OF_FORM_AFTER_PANEL;

            // Credit label location.
            label_SuperMathCredit.Location = new Point(
                this.ClientRectangle.Width - HORIZONAL_DISTANCE_OF_CREDIT_LABEL_FROM_DOWN_RIGHT_FORM_POINT
                - label_SuperMathCredit.Width,
                panel.Location.Y + panel.Height +
                VERTICAL_DISTANCE_OF_CREDIT_LABEL_FROM_DOWN_RIGHT_PANEL);
            label_SuperMathCredit.Visible = true;

            // Change label of "Pick Server" location.
            label_ChooseServer.Location = new Point(startOfPanelX, //DISTANCE_OF_LABEL_FROM_LEFT_EDGE,
                                                                   //this.ClientRectangle.Width - DISTANCE_OF_LABEL_FROM_RIGHT_EDGE- label_ChooseServer.Width,
                                                    label_ChooseServer.Location.Y);

            // Set pictureBox_UpdateButton Location.
            pictureBox_UpdateButton.Location = new Point(startOfPanelX + panel.Width - pictureBox_UpdateButton.Width, //this.ClientRectangle.Width -
                                                                                                                      //DISTANCE_OF_LABEL_FROM_RIGHT_EDGE - pictureBox_UpdateButton.Width,
                                                         Y_LOCATION_OF_UPDATE_BUTTON);

            // Set form height.
            this.Height = label_SuperMathCredit.Location.Y +
                          +label_SuperMathCredit.Height + VERTICAL_DISTANCE_AFTER_CREDIT_LABEL;

            // Display form in the center of the screen.
            this.Location = new Point(
                (Screen.PrimaryScreen.WorkingArea.Width / 2) - (this.Width / 2),
                (Screen.PrimaryScreen.WorkingArea.Height / 2) - (this.Height / 2));
        }