public CalculatorControl(decimal startingValue, bool CloseButtonVisible = false) : base()
        {
            Value = startingValue;

            current_command = Value.ToString();

            var doc = document.createDocumentFragment();

            int AddHeight = (Helper.NotDesktop ? 45 : 22);

            //27.77778

            doc.appendChild(
                (DisplayInput = new MemoInput()
            {
                Readonly = true,
                Bounds = new Vector4(4, 4, "(100% - 8px)", AddHeight)
            }).Content
                );

            if (Helper.NotDesktop)
            {
                DisplayInput.Style.fontSize = "14px";
                DisplayInput.Height         = 45;
            }

            List <SimpleButton> buttons = new List <SimpleButton>();

            buttons.AddRange(
                new SimpleButton[] {
                btnPTAX = new SimpleButton()
                {
                    Text      = "+TAX",
                    ItemClick = AddOperator
                },
                btn7 = new SimpleButton()
                {
                    Text      = "7",
                    ItemClick = AddTextToCommand
                },
                btn8 = new SimpleButton()
                {
                    Text      = "8",
                    ItemClick = AddTextToCommand
                },
                btn9 = new SimpleButton()
                {
                    Text      = "9",
                    ItemClick = AddTextToCommand
                },
                btnDiv = new SimpleButton()
                {
                    Text      = "/",
                    ItemClick = AddOperator
                },
                btnSqrt = new SimpleButton()
                {
                    Text      = "sqrt",
                    ItemClick = AddOperator
                },
                btnMTAX = new SimpleButton()
                {
                    Text      = "-TAX",
                    ItemClick = AddOperator
                },
                btn4 = new SimpleButton()
                {
                    Text      = "4",
                    ItemClick = AddTextToCommand
                },
                btn5 = new SimpleButton()
                {
                    Text      = "5",
                    ItemClick = AddTextToCommand
                },
                btn6 = new SimpleButton()
                {
                    Text      = "6",
                    ItemClick = AddTextToCommand
                },
                btnMul = new SimpleButton()
                {
                    Text      = "*",
                    ItemClick = AddOperator
                },
                btnPer = new SimpleButton()
                {
                    Text      = "%",
                    ItemClick = AddOperator
                },
                btnTAX = new SimpleButton()
                {
                    Text      = "TAX",
                    ItemClick = AddOperator
                },
                btn1 = new SimpleButton()
                {
                    Text      = "1",
                    ItemClick = AddTextToCommand
                },
                btn2 = new SimpleButton()
                {
                    Text      = "2",
                    ItemClick = AddTextToCommand
                },
                btn3 = new SimpleButton()
                {
                    Text      = "3",
                    ItemClick = AddTextToCommand
                },
                btnMinus = new SimpleButton()
                {
                    Text      = "-",
                    ItemClick = AddOperator
                },
                btn1OverX = new SimpleButton()
                {
                    Text      = "1/x",
                    ItemClick = AddOperator
                },
                btnDbl = new SimpleButton()
                {
                    Text      = "Dbl",
                    ItemClick = AddOperator
                },
                btn0 = new SimpleButton()
                {
                    Text      = "0",
                    ItemClick = AddTextToCommand
                },
                btnplusOrNeg = new SimpleButton()
                {
                    Text      = "+/-",
                    ItemClick = AddOperator
                },
                btnDot = new SimpleButton()
                {
                    Text      = ".",
                    ItemClick = AddTextToCommand
                },
                btnPlus = new SimpleButton()
                {
                    Text      = "+",
                    ItemClick = AddOperator
                },
                btnEq = new SimpleButton()
                {
                    Text      = "=",
                    ItemClick = AddOperator
                }
            }
                );
            int index   = 0;
            int y       = 0;
            int yOffset = 28 + AddHeight;

            btnClose = new SimpleButton()
            {
                Text      = "&times;",
                Size      = new Vector2("((100% - 28px) * 0.1666666666666667)", "((100% - " + yOffset + "px) * 0.2)"),
                Location  = new Vector2("(((100% - 28px) * " + (5 * 0.1666666666666667m) + ") + " + ((5 * 4) + 4) + "px)", "(((100% - " + yOffset + "px) * " + (y * 0.2m) + ") + " + (((y * 4) + 8) + AddHeight) + "px)"),
                ItemClick = (ev) =>
                {
                    if (OnClose != null)
                    {
                        OnClose();
                    }
                }
            };
            if (Helper.NotDesktop)
            {
                btnClose.Style.fontSize   = "26px";
                btnClose.Style.fontWeight = "bold";
            }
            btnBack = new SimpleButton()
            {
                Text      = "Back",
                Size      = new Vector2("(((100% - 24px) - ((100% - 28px) * 0.1666666666666667)) * 0.333)", "((100% - " + yOffset + "px) * 0.2)"),
                Location  = new Vector2("(((((100% - 24px) - ((100% - 28px) * 0.1666666666666667)) * 0.333) * 0) + 4px)", "(((100% - " + yOffset + "px) * " + (y * 0.2m) + ") + " + (((y * 4) + 8) + AddHeight) + "px)"),
                ItemClick = Back
            };
            if (Helper.NotDesktop)
            {
                btnBack.Style.fontSize = "14px";
            }
            btnCE = new SimpleButton()
            {
                Text      = "CE",
                Size      = new Vector2("(((100% - 24px) - ((100% - 28px) * 0.1666666666666667)) * 0.333)", "((100% - " + yOffset + "px) * 0.2)"),
                Location  = new Vector2("(((((100% - 24px) - ((100% - 28px) * 0.1666666666666667)) * 0.333) * 1) + 8px)", "(((100% - " + yOffset + "px) * " + (y * 0.2m) + ") + " + (((y * 4) + 8) + AddHeight) + "px)"),
                ItemClick = (ev) =>
                {
                    current_command = "";
                    RefreshValue();
                }
            };
            if (Helper.NotDesktop)
            {
                btnCE.Style.fontSize = "14px";
            }
            btnC = new SimpleButton()
            {
                Text      = "C",
                Size      = new Vector2("((((100% - 24px) - ((100% - 28px) * 0.1666666666666667)) * 0.333) + 4px)", "((100% - " + yOffset + "px) * 0.2)"),
                Location  = new Vector2("(((((100% - 24px) - ((100% - 28px) * 0.1666666666666667)) * 0.333) * 2) + 12px)", "(((100% - " + yOffset + "px) * " + (y * 0.2m) + ") + " + (((y * 4) + 8) + AddHeight) + "px)"),
                ItemClick = (ev) =>
                {
                    _commands = new List <string>(); current_command = "";
                    RefreshValue();
                }
            };
            if (Helper.NotDesktop)
            {
                btnC.Style.fontSize = "14px";
            }

            doc.AppendChildren(btnClose.Content, btnBack.Content, btnCE.Content, btnC.Content);

            y++;

            for (int i = 0; i < buttons.Count; i++)
            {
                buttons[i].Size     = new Vector2("((100% - 28px) * 0.1666666666666667)", "((100% - " + yOffset + "px) * 0.2)");
                buttons[i].Location = new Vector2("(((100% - 28px) * " + (index * 0.1666666666666667m) + ") + " + ((index * 4) + 4) + "px)", "(((100% - " + yOffset + "px) * " + (y * 0.2m) + ") + " + (((y * 4) + 8) + AddHeight) + "px)");
                if (Helper.NotDesktop)
                {
                    buttons[i].Style.fontSize = "14px";
                }

                doc.appendChild(buttons[i].Content);
                index++;
                if (index == 6)
                {
                    index = 0;
                    y++;
                }
            }

            btnDbl.Style.fontSize  = "6.5pt";
            btnTAX.Style.fontSize  = "6.5pt";
            btnPTAX.Style.fontSize = "6.5pt";
            btnMTAX.Style.fontSize = "6.5pt";

            btnClose.Style.color      = "red";
            btnClose.Style.fontWeight = "bold";

            if (!CloseButtonVisible)
            {
                btnClose.Style.visibility = "hidden";
            }

            RefreshValue();

            Content.appendChild(doc);
        }
        public void AddOperator(SimpleButton button)
        {
            if (IsSingleOperator(button.Text))
            {
                if (_commands.Count > 0)
                {
                    var x = _commands.Last();
                    if (!IsSingleOperator(x))
                    {
                        if (current_command == "" && !IsAllNumbers(x))
                        {
                            return;
                        }
                    }
                }

                if (current_command != "")
                {
                    _commands.Add(current_command);
                    current_command = "";
                }

                _commands.Add(button.Text);

                RefreshValue();
            }
            else
            {
                if (current_command == "")
                {
                    if (button.Text == "=")
                    {
                        CalculateAndClose();
                        return;
                    }
                    else
                    {
                        if (_commands.Count > 0)
                        {
                            var x = _commands.Last();
                            if (!IsSingleOperator(x))
                            {
                                return;
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                }

                if (button.Text == "%")
                {
                    if (_commands.Count > 0)
                    {
                        var x = _commands.Last();

                        if (!IsSingleOperator(x))
                        {
                            current_command += "%";
                            _commands.Add(current_command);
                            current_command = "";
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                else
                {
                    _commands.Add(current_command);
                    current_command = "";

                    if (button.Text == "=")
                    {
                        CalculateAndClose();
                    }
                    else
                    {
                        _commands.Add(button.Text);
                    }
                }
                RefreshValue();
            }
        }