private void ClickEventForNewButton(object sender, EventArgs e)
        {
            Button        senderButton = sender as Button;
            ControlObject parentObject = new ControlObject();

            // Get parent object.
            foreach (ControlObject c in mainFM.AllObjects)
            {
                if (c.rootObject.Name == senderButton.Name)
                {
                    parentObject = c;
                }
            }

            switch ((Int32)senderButton.Tag)
            {
            case (Int32)ButtonActionIndex.SendSerial:
            {
                string text = "";
                // Select where the serial message shall come from.
                switch (parentObject.local_buttonAction.messageSourceIndex)
                {
                case (Int32)SendOnClickMessageSourceIndex.HardSetMessage:
                {
                    text = parentObject.local_buttonAction.serialMessageToSend;
                    break;
                }

                case (Int32)SendOnClickMessageSourceIndex.FromComboBox:
                case (Int32)SendOnClickMessageSourceIndex.FromTextBox:
                {
                    text = parentObject.local_buttonAction.sourceObject.rootObject.Text;

                    break;
                }
                }

                Serial_functions.SendCommand(text);
                break;
            }

            case (Int32)ButtonActionIndex.OpenClosePort:
            {
                Serial_functions.OpenClosePort();
                break;
            }

            case (Int32)ButtonActionIndex.ShowHideObject:
            {
                bool current = parentObject.local_buttonAction.targetObject.rootObject.Visible;

                parentObject.local_buttonAction.targetObject.rootObject.Visible = !current;

                break;
            }
            }
        }
        // Create new object.
        private void cmd_createObject_Click(object sender, EventArgs e)
        {
            #region Locales.
            dynamic newRootObject = null;

            Color
                textColor = pan_textColor.BackColor,
                backColor = pan_backColor.BackColor;

            string
                objectName    = txt_objectName.Text,
                objectContent = txt_content.Text;

            bool
                textBoxShallBeReadOnly = chb_textBoxIsReadOnly.Checked;

            int
                newObjectIndex      = cob_objectType.SelectedIndex,
                parentFunctionIndex = cob_chooseFunction.SelectedIndex,

                x_pos = Convert.ToInt32(txt_xPos.Text),
                y_pos = Convert.ToInt32(txt_yPos.Text),
                width = Convert.ToInt32(txt_width.Text);
            #endregion

            Point newLocation = new Point(x_pos, y_pos);

            ControlObject newObject = new ControlObject()
            {
                objectIndex     = newObjectIndex,
                rootObject      = newRootObject,
                commonBackColor = backColor,
                commonFontColor = textColor
            };

            switch (newObjectIndex)
            {
            case (Int32)ObjectIndex.Label:
            {
                Label newLabel = new Label()
                {
                    Name      = "lbl_" + objectName,
                    Text      = objectContent,
                    Location  = newLocation,
                    BackColor = backColor,
                    ForeColor = textColor
                };

                if (!chb_autoSize.Checked)
                {
                    newLabel.Width = width;
                }
                else
                {
                    newLabel.AutoSize = true;
                }

                newObject.parentFunction = mainFM.AllFunctions[parentFunctionIndex];
                newRootObject            = newLabel;
                newObject.rootObject     = newRootObject;

                break;
            }

            case (Int32)ObjectIndex.Textbox:
            {
                TextBox newTextBox = new TextBox()
                {
                    Name      = "txt_" + objectName,
                    Text      = objectContent,
                    Location  = newLocation,
                    Width     = width,
                    BackColor = backColor,
                    ForeColor = textColor
                };

                newRootObject        = newTextBox;
                newObject.rootObject = newRootObject;

                break;
            }

            case (Int32)ObjectIndex.Combo:
            {
                break;
            }

            case (Int32)ObjectIndex.Button:
            {
                Button newButton = new Button()
                {
                    Name      = "cmd_" + objectName,
                    Text      = objectContent,
                    Location  = newLocation,
                    Width     = width,
                    BackColor = backColor,
                    ForeColor = textColor,
                };

                newButton.Tag    = this.buttonAction;
                newButton.Click += new EventHandler(ClickEventForNewButton);

                ButtonAction localButton = new ButtonAction()
                {
                    actionIndex        = this.buttonAction,
                    messageSourceIndex = cob_sendSerialSource.SelectedIndex,
                    mouseKeyIndex      = MouseClickIndex.SingleClick,

                    sourceObject = GetSourceObjectForButton(),
                    targetObject = GetTargetObjectForButton(),
                };

                newRootObject = newButton;
                newObject.local_buttonAction = localButton;
                newObject.rootObject         = newRootObject;

                break;
            }

            case (Int32)ObjectIndex.Invalid:
            {
                // Object is invalid and will not be created.
                break;
            }
            }

            mainFM.AllObjects.Add(newObject);
            mainFM.ref_playground.Controls.Add(newRootObject);
            mainFM.AllFunctions[parentFunctionIndex].targetObjects.Add(newRootObject);

            // Hide preview items on the playground.
            mainFM.ref_playground.lbl_preview.Visible         =
                mainFM.ref_playground.cmd_preview.Visible     =
                    mainFM.ref_playground.txt_preview.Visible = false;

            // Restore objects on the form.
            txt_content.Text                 =
                txt_objectName.Text          = "";
            cob_chooseFunction.SelectedIndex =
                cob_objectType.SelectedIndex = -1;
        }