Forex_Strategy_Builder.Edit_Translation.OnResize C# (CSharp) Method

OnResize() protected method

Recalculates the sizes and positions of the controls after resizing.
protected OnResize ( EventArgs e ) : void
e System.EventArgs
return void
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            int buttonHeight = (int)(Data.VerticalDLU * 15.5);
            int buttonWidth  = (int)(Data.HorizontalDLU * 60);
            int btnVertSpace = (int)(Data.VerticalDLU * 5.5);
            int btnHrzSpace  = (int)(Data.HorizontalDLU * 3);
            int border       = btnHrzSpace;
            int textHeight   = Font.Height;

            // pnlCommon
            pnlCommon.Size     = new Size(ClientSize.Width - 2 * border, 85);
            pnlCommon.Location = new Point(border, border);

            Graphics g = CreateGraphics();
            int maxLabelLenght = 0;
            foreach (Label label in alblInputNames)
            {
                int lenght = (int)g.MeasureString(label.Text, Font).Width;
                if (lenght > maxLabelLenght)
                    maxLabelLenght = lenght;
            }
            g.Dispose();

            int labelWidth   = maxLabelLenght + border;
            int textBoxWidth = (pnlCommon.ClientSize.Width - 4 * border - 3 * labelWidth) / 3;

            int shift     = 26;
            int vertSpace = 2;
            int number    = 0;
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (i == 0 && j == 2) continue;

                    int xLabel   = border + j * (labelWidth + textBoxWidth) + j * border;
                    int yLabel   = i * buttonHeight + (i + 1) * vertSpace + shift;
                    int xTextBox = border + labelWidth + j * (labelWidth + textBoxWidth) + j * border;
                    int yTextBox = i * buttonHeight + (i + 1) * vertSpace + shift - 2;

                    alblInputNames[number].Location  = new Point(xLabel,   yLabel);

                    atbxInputValues[number].Width    = textBoxWidth;
                    atbxInputValues[number].Location = new Point(xTextBox, yTextBox);

                    number++;
                }
            }

            atbxInputValues[0].Enabled = false;
            atbxInputValues[1].Enabled = false;

            // pnlPhrases
            pnlPhrases.Size = new Size(ClientSize.Width - 2 * border, ClientSize.Height - buttonHeight - 2 * btnVertSpace - border - pnlCommon.Bottom);
            pnlPhrases.Location = new Point(border, pnlCommon.Bottom + border);

            shift = 22;
            textBoxWidth = (pnlPhrases.ClientSize.Width - 4 * border - scrollBar.Width) / 2;
            int iTextBoxHeight = (pnlPhrases.ClientSize.Height - shift - (TEXTBOXES + 1) * border) / TEXTBOXES;

            for (int i = 0; i < TEXTBOXES; i++)
            {
                int xMain = border;
                int yMain = i * iTextBoxHeight + (i + 1) * border + shift;
                int xAlt  = 2 * border + textBoxWidth;
                int yAlt  = i * iTextBoxHeight + (i + 1) * border + shift;

                atbxMain[i].Size     = new Size(textBoxWidth, iTextBoxHeight);
                atbxAlt[i].Size      = new Size(textBoxWidth, iTextBoxHeight);
                atbxMain[i].Location = new Point(xMain, yMain);
                atbxAlt[i].Location  = new Point(xAlt,  yAlt);
            }

            scrollBar.Height   = atbxAlt[TEXTBOXES - 1].Bottom - atbxAlt[0].Top;
            scrollBar.Location = new Point(pnlPhrases.ClientSize.Width - border - scrollBar.Width, atbxAlt[0].Top);

            // tbxSearch
            tbxSearch.Size     = new Size(3 * buttonWidth / 2, buttonHeight);
            tbxSearch.Location = new Point(btnHrzSpace, ClientSize.Height - buttonHeight - btnVertSpace + 2);

            // Button Search
            btnSearch.Size     = new Size(buttonWidth, buttonHeight);
            btnSearch.Location = new Point(tbxSearch.Right + btnHrzSpace, ClientSize.Height - buttonHeight - btnVertSpace);

            // Button Untranslated
            btnUntranslated.Size     = new Size(buttonWidth, buttonHeight);
            btnUntranslated.Location = new Point(btnSearch.Right + btnHrzSpace, ClientSize.Height - buttonHeight - btnVertSpace);

            // Button Cancel
            btnCancel.Size     = new Size(buttonWidth, buttonHeight);
            btnCancel.Location = new Point(ClientSize.Width - buttonWidth - btnHrzSpace, ClientSize.Height - buttonHeight - btnVertSpace);

            // Button Accept
            btnAccept.Size     = new Size(buttonWidth, buttonHeight);
            btnAccept.Location = new Point(btnCancel.Left - buttonWidth - btnHrzSpace, ClientSize.Height - buttonHeight - btnVertSpace);

            return;
        }