Exemple #1
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            Text              = "Calculator";
            lblMain           = CreateLabel("0", ContentAlignment.MiddleRight, mainLabelFont);
            lblMemory         = CreateLabel("M", ContentAlignment.MiddleLeft, mainLabelFont);
            lblTemp           = CreateLabel("", ContentAlignment.BottomRight, tempLabelFont);
            lblMemory.Visible = false;


            MyPanel            mainPanel     = new MyPanel(DockStyle.Fill, new Padding(4), Color.Transparent);
            MyTableLayoutPanel mainContainer = new MyTableLayoutPanel(7, 10, DockStyle.Fill, Color.White);

            mainContainer.SetRowDimension(SizeType.Percent, 20, 13, 13, 13, 13, 13, 13);
            mainContainer.SetColumnDimension(SizeType.Percent, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10);
            mainContainer.SetGradientBackground(calcColor2, calcColor1, 90f);
            MyTableLayoutPanel displayPanel = new MyTableLayoutPanel(2, 2, DockStyle.Fill, new Padding(10), Color.Transparent);

            displayPanel.SetBorderAndGradientBackground(new Pen(calcBorderColor, 2), calcColor1, calcColor2, 90f);
            displayPanel.SetRowDimension(SizeType.Percent, 30, 70);
            displayPanel.SetColumnDimension(SizeType.Percent, 10, 90);


            displayPanel.Controls.Add(lblTemp, 1, 0);
            displayPanel.Controls.Add(lblMain, 1, 1);
            displayPanel.Controls.Add(lblMemory, 0, 0);
            displayPanel.SetRowSpan(lblMemory, 2);

            mainContainer.Controls.Add(displayPanel, 0, 0);
            mainContainer.SetColumnSpan(displayPanel, 10);


            MyTableLayoutPanel degRadGradPanel = new MyTableLayoutPanel(1, 3, DockStyle.Fill, new Padding(3));

            degRadGradPanel.SetColumnDimension(SizeType.Percent, 36, 36, 27);
            degRadGradPanel.SetBorder(new Pen(calcBorderColor, 2));

            RadioButton degButton  = CreateRadioButton("Degrees");
            RadioButton radButton  = CreateRadioButton("Radians", true);
            RadioButton gradButton = CreateRadioButton("Gradians");

            degButton.Click  += (s, args) => angleMode = AngleMode.Degree;
            radButton.Click  += (s, args) => angleMode = AngleMode.Radian;
            gradButton.Click += (s, args) => angleMode = AngleMode.Gradient;

            degRadGradPanel.Controls.Add(degButton, 0, 0);
            degRadGradPanel.Controls.Add(radButton, 1, 0);
            degRadGradPanel.Controls.Add(gradButton, 2, 0);

            mainContainer.Controls.Add(degRadGradPanel, 0, 1);
            mainContainer.SetColumnSpan(degRadGradPanel, 5);


            Button btnMc = CreateButton("MC");
            Button btnMr = CreateButton("MR");
            Button btnMs = CreateButton("MS");
            Button btnMp = CreateButton("M+");
            Button btnMm = CreateButton("M-");

            mainContainer.Controls.Add(btnMc, 5, 1);
            mainContainer.Controls.Add(btnMr, 6, 1);
            mainContainer.Controls.Add(btnMs, 7, 1);
            mainContainer.Controls.Add(btnMp, 8, 1);
            mainContainer.Controls.Add(btnMm, 9, 1);

            MyPanel emptyPanel = new MyPanel(DockStyle.Fill, Padding.Empty, Color.Transparent);

            emptyPanel.SetBorder(new Pen(calcBorderColor, 1));

            Button btnE         = CreateButton("e");
            Button btnLn        = CreateButton("ln");
            Button btnRnd       = CreateButton("Rnd");
            Button btnEToX      = CreateButton("eⁿ");
            Button btnBksp      = CreateButton("←");
            Button btnCE        = CreateButton("CE");
            Button btnC         = CreateButton("C");
            Button btnPlusMinus = CreateButton("±");
            Button btnSqrt      = CreateButton("√");

            mainContainer.Controls.Add(emptyPanel, 0, 2);
            mainContainer.Controls.Add(btnE, 1, 2);
            mainContainer.Controls.Add(btnLn, 2, 2);
            mainContainer.Controls.Add(btnRnd, 3, 2);
            mainContainer.Controls.Add(btnEToX, 4, 2);
            mainContainer.Controls.Add(btnBksp, 5, 2);
            mainContainer.Controls.Add(btnCE, 6, 2);
            mainContainer.Controls.Add(btnC, 7, 2);
            mainContainer.Controls.Add(btnPlusMinus, 8, 2);
            mainContainer.Controls.Add(btnSqrt, 9, 2);


            Button btnInt     = CreateButton("Int");
            Button btnSinh    = CreateButton("sinh");
            Button btnSin     = CreateButton("sin");
            Button btnXsquare = CreateButton("x²");
            Button btnFact    = CreateButton("n!");
            Button btn7       = CreateButton("7");
            Button btn8       = CreateButton("8");
            Button btn9       = CreateButton("9");
            Button btnDiv     = CreateButton("/");
            Button btnPercent = CreateButton("%");

            mainContainer.Controls.Add(btnInt, 0, 3);
            mainContainer.Controls.Add(btnSinh, 1, 3);
            mainContainer.Controls.Add(btnSin, 2, 3);
            mainContainer.Controls.Add(btnXsquare, 3, 3);
            mainContainer.Controls.Add(btnFact, 4, 3);
            mainContainer.Controls.Add(btn7, 5, 3);
            mainContainer.Controls.Add(btn8, 6, 3);
            mainContainer.Controls.Add(btn9, 7, 3);
            mainContainer.Controls.Add(btnDiv, 8, 3);
            mainContainer.Controls.Add(btnPercent, 9, 3);

            Button btnDms     = CreateButton("dms");
            Button btnCosh    = CreateButton("cosh");
            Button btnCos     = CreateButton("cos");
            Button btnXPowerN = CreateButton("xⁿ");
            Button btnYRootX  = CreateButton("ⁿ√x");
            Button btn4       = CreateButton("4");
            Button btn5       = CreateButton("5");
            Button btn6       = CreateButton("6");
            Button btnMult    = CreateButton("*");
            Button btn1ByX    = CreateButton("1/x");

            mainContainer.Controls.Add(btnDms, 0, 4);
            mainContainer.Controls.Add(btnCosh, 1, 4);
            mainContainer.Controls.Add(btnCos, 2, 4);
            mainContainer.Controls.Add(btnXPowerN, 3, 4);
            mainContainer.Controls.Add(btnYRootX, 4, 4);
            mainContainer.Controls.Add(btn4, 5, 4);
            mainContainer.Controls.Add(btn5, 6, 4);
            mainContainer.Controls.Add(btn6, 7, 4);
            mainContainer.Controls.Add(btnMult, 8, 4);
            mainContainer.Controls.Add(btn1ByX, 9, 4);


            Button btnPi         = CreateButton("Pi");
            Button btnTanh       = CreateButton("tanh");
            Button btnTan        = CreateButton("tan");
            Button btnXCube      = CreateButton("x³");
            Button btnThirdRootX = CreateButton("³√x");
            Button btn1          = CreateButton("1");
            Button btn2          = CreateButton("2");
            Button btn3          = CreateButton("3");
            Button btnMinus      = CreateButton("-");
            Button btnEquals     = CreateButton("=");

            mainContainer.Controls.Add(btnPi, 0, 5);
            mainContainer.Controls.Add(btnTanh, 1, 5);
            mainContainer.Controls.Add(btnTan, 2, 5);
            mainContainer.Controls.Add(btnXCube, 3, 5);
            mainContainer.Controls.Add(btnThirdRootX, 4, 5);
            mainContainer.Controls.Add(btn1, 5, 5);
            mainContainer.Controls.Add(btn2, 6, 5);
            mainContainer.Controls.Add(btn3, 7, 5);
            mainContainer.Controls.Add(btnMinus, 8, 5);
            mainContainer.Controls.Add(btnEquals, 9, 5);
            mainContainer.SetRowSpan(btnEquals, 2);


            CheckBox btnFE    = CreateCheckBox("F-E");
            Button   btnExp   = CreateButton("Exp");
            Button   btnMod   = CreateButton("Mod");
            Button   btnLog   = CreateButton("log");
            Button   btn10ToX = CreateButton("10ⁿ");
            Button   btn0     = CreateButton("0");
            Button   btnDot   = CreateButton(".");
            Button   btnPlus  = CreateButton("+");

            mainContainer.Controls.Add(btnFE, 0, 6);
            mainContainer.Controls.Add(btnExp, 1, 6);
            mainContainer.Controls.Add(btnMod, 2, 6);
            mainContainer.Controls.Add(btnLog, 3, 6);
            mainContainer.Controls.Add(btn10ToX, 4, 6);
            mainContainer.Controls.Add(btn0, 5, 6);
            mainContainer.SetColumnSpan(btn0, 2);
            mainContainer.Controls.Add(btnDot, 7, 6);
            mainContainer.Controls.Add(btnPlus, 8, 6);


            mainPanel.Controls.Add(mainContainer);
            this.Controls.Add(mainPanel);

            btnBksp.Click += (s, args) => {
                if (lblMain.Text.Length == 1)
                {
                    lblMain.Text = "0";
                }
                else
                {
                    lblMain.Text = lblMain.Text.Substring(0, lblMain.Text.Length - 1);
                }
            };
            btnCE.Click += (s, args) => {
                lblMain.Text = "0";
                if (isLastUnary)
                {
                    lblTemp.Text = unaryTemp;
                }
                unaryTemp = "";
                unaryExp  = "";
            };

            btnC.Click += (s, args) => {
                currentFunction = Function.None;
                lblMain.Text    = "0";
                lblTemp.Text    = "";
                unaryExp        = "";
                unaryTemp       = "";
            };
            btnEquals.Click += (s, args) => {
                current = Convert.ToDouble(lblMain.Text);
                EvaluatePending();
                lblTemp.Text    = "";
                currentFunction = Function.None;
                isOverwrite     = true;
            };
            btnDot.Click += (s, args) => { if (!isDecimal)
                                           {
                                               MainInput(".");
                                           }
                                           isDecimal = true; };

            btnPlusMinus.Click += (s, args) => {
                if (lblMain.Text[0] == '-')
                {
                    lblMain.Text = lblMain.Text.Substring(1);
                }
                else
                {
                    lblMain.Text = '-' + lblMain.Text;
                }
            };
            btnMs.Click += (s, args) => {
                userMemory        = Convert.ToDouble(lblMain.Text);
                lblMemory.Visible = true;
                isOverwrite       = true;
                isMemorySet       = true;
            };
            btnMc.Click += (s, args) => {
                userMemory        = 0;
                lblMemory.Visible = false;
                isMemorySet       = false;
            };
            btnMr.Click += (s, args) => {
                lblMain.Text = userMemory.ToString();
                isOverwrite  = true;
            };
            btnMp.Click += (s, args) => {
                if (isMemorySet)
                {
                    userMemory  += Convert.ToDouble(lblMain.Text);
                    lblMain.Text = userMemory.ToString();
                    isOverwrite  = true;
                }
            };
            btnMm.Click += (s, args) => {
                if (isMemorySet)
                {
                    userMemory  -= Convert.ToDouble(lblMain.Text);
                    lblMain.Text = userMemory.ToString();
                    isOverwrite  = true;
                }
            };


            btnFE.Click += (s, args) => {
                isScientific = btnFE.Checked;
                FunctionInputUnary(Function.Exponential);
                isOverwrite = true;
            };


            btn1.Click += (s, args) => MainInput("1");
            btn2.Click += (s, args) => MainInput("2");
            btn3.Click += (s, args) => MainInput("3");
            btn4.Click += (s, args) => MainInput("4");
            btn5.Click += (s, args) => MainInput("5");
            btn6.Click += (s, args) => MainInput("6");
            btn7.Click += (s, args) => MainInput("7");
            btn8.Click += (s, args) => MainInput("8");
            btn9.Click += (s, args) => MainInput("9");
            btn0.Click += (s, args) => MainInput("0");



            btnPlus.Click    += (s, args) => FunctionInput(Function.Addition);
            btnMinus.Click   += (s, args) => FunctionInput(Function.Subtraction);
            btnMult.Click    += (s, args) => FunctionInput(Function.Multiplication);
            btnDiv.Click     += (s, args) => FunctionInput(Function.Division);
            btnMod.Click     += (s, args) => FunctionInput(Function.Mod);
            btnXPowerN.Click += (s, args) => FunctionInput(Function.XToY);
            btnYRootX.Click  += (s, args) => FunctionInput(Function.YRootX);

            btn10ToX.Click      += (s, args) => FunctionInputUnary(Function.Power10);
            btnLog.Click        += (s, args) => FunctionInputUnary(Function.Log10);
            btnExp.Click        += (s, args) => FunctionInputUnary(Function.Exponential);
            btnThirdRootX.Click += (s, args) => FunctionInputUnary(Function.ThirdRootX);
            btnXCube.Click      += (s, args) => FunctionInputUnary(Function.XCube);
            btnTanh.Click       += (s, args) => FunctionInputUnary(Function.TanH);
            btnTan.Click        += (s, args) => FunctionInputUnary(Function.Tan);
            btnPi.Click         += (s, args) => FunctionInputUnary(Function.Pi);
            btnCosh.Click       += (s, args) => FunctionInputUnary(Function.CosH);
            btnCos.Click        += (s, args) => FunctionInputUnary(Function.Cos);
            btnSinh.Click       += (s, args) => FunctionInputUnary(Function.SinH);
            btnSin.Click        += (s, args) => FunctionInputUnary(Function.Sin);
            btnDms.Click        += (s, args) => FunctionInputUnary(Function.Dms);
            btnFact.Click       += (s, args) => FunctionInputUnary(Function.Factorial);
            btnXsquare.Click    += (s, args) => FunctionInputUnary(Function.XSquare);
            btnInt.Click        += (s, args) => FunctionInputUnary(Function.Int);
            btnLn.Click         += (s, args) => FunctionInputUnary(Function.LogE);
            btnRnd.Click        += (s, args) => FunctionInputUnary(Function.Random);
            btnEToX.Click       += (s, args) => FunctionInputUnary(Function.EToX);
            btnE.Click          += (s, args) => FunctionInputUnary(Function.E);
            btn1ByX.Click       += (s, args) => FunctionInputUnary(Function.OneByX);
            btnSqrt.Click       += (s, args) => FunctionInputUnary(Function.SquareRoot);
            btnPercent.Click    += (s, args) => FunctionInputUnary(Function.Percent);
        }
Exemple #2
0
        private void Init()
        {
            Text = "Facebook - Login & SignUp";
            MyTableLayoutPanel mainPanel = new MyTableLayoutPanel(2, 1, DockStyle.Fill);
            MyTableLayoutPanel topPanel  = new MyTableLayoutPanel(1, 3, DockStyle.Fill, new Padding(10), Color.DarkBlue)
            {
                AutoSize = true
            };

            topPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20));
            topPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            topPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));

            TableLayoutPanel loginContainer = new TableLayoutPanel()
            {
                RowCount    = 2,
                ColumnCount = 3,
                Dock        = DockStyle.Right,
                AutoSize    = true
            };

            loginContainer.Controls.Add(new Label()
            {
                Text      = "Email Or Phone",
                ForeColor = Color.White
            }, 0, 0);

            txtLoginMobile = new TextBox()
            {
            };

            loginContainer.Controls.Add(txtLoginMobile, 0, 1);

            loginContainer.Controls.Add(new Label()
            {
                Text      = "Password",
                ForeColor = Color.White
            }, 1, 0);

            txtLoginPassword = new TextBox()
            {
                PasswordChar = '*'
            };

            loginContainer.Controls.Add(txtLoginPassword, 1, 1);

            Button btnLogin = new Button()
            {
                Text      = "Log In",
                ForeColor = Color.White,
            };

            btnLogin.Click += BtnLogin_Click;

            loginContainer.Controls.Add(btnLogin, 2, 1);

            topPanel.Controls.Add(loginContainer, 2, 0);
            topPanel.Controls.Add(new Label()
            {
                Text      = "facebook",
                Font      = new Font("Helvetica", 30, FontStyle.Bold),
                ForeColor = Color.White,
                AutoSize  = true
            }, 1, 0);

            MyTableLayoutPanel bottomPanel = new MyTableLayoutPanel(1, 2, DockStyle.Fill);

            bottomPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            bottomPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            bottomPanel.SetGradientBackground(Color.White, System.Drawing.Color.FromArgb(211, 216, 232), 90f);

            Panel bottomLeftPanel = new Panel()
            {
                Dock                  = DockStyle.Fill,
                BackgroundImage       = Image.FromFile(Environment.CurrentDirectory + "\\Images\\bg.png"),
                BackgroundImageLayout = ImageLayout.Zoom
            };

            MyTableLayoutPanel bottomRightPanel = new MyTableLayoutPanel(10, 1, DockStyle.Fill);

            bottomRightPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
            bottomRightPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            bottomRightPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            bottomRightPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            bottomRightPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            bottomRightPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            bottomRightPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            bottomRightPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            bottomRightPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            bottomRightPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
            bottomRightPanel.AutoSize = true;

            bottomRightPanel.Controls.Add(new Label()
            {
                Text     = "Create an account",
                Font     = new Font("Helvetica", 20, FontStyle.Bold),
                AutoSize = true
            }, 0, 0);

            bottomRightPanel.Controls.Add(new Label()
            {
                Text     = "It's quick and easy.",
                Font     = new Font("Helvetica", 10),
                AutoSize = true
            }, 0, 1);

            txtName = new TextBox()
            {
                Text      = "First Name",
                Dock      = DockStyle.Fill,
                Font      = new Font("Helvetica", 15),
                ForeColor = Color.Gray
            };

            txtSurName = new TextBox()
            {
                Text      = "Surname",
                Dock      = DockStyle.Fill,
                Font      = new Font("Helvetica", 15),
                ForeColor = Color.Gray
            };

            txtMobile = new TextBox()
            {
                Text      = "Mobile Or Email",
                Dock      = DockStyle.Fill,
                Font      = new Font("Helvetica", 15),
                ForeColor = Color.Gray
            };

            txtPassword = new TextBox()
            {
                Text      = "New Password",
                Dock      = DockStyle.Fill,
                Font      = new Font("Helvetica", 15),
                ForeColor = Color.Gray
            };

            txtName.Enter     += (s, args) => txtName.Text = txtName.Text == "First Name" ? "" : txtName.Text;
            txtName.Leave     += (s, args) => txtName.Text = txtName.Text == "" ? "First Name" : txtName.Text;
            txtSurName.Enter  += (s, args) => txtSurName.Text = txtSurName.Text == "Surname" ? "" : txtSurName.Text;
            txtSurName.Leave  += (s, args) => txtSurName.Text = txtSurName.Text == "" ? "Surname" : txtSurName.Text;
            txtMobile.Enter   += (s, args) => txtMobile.Text = txtMobile.Text == "Mobile Or Email" ? "" : txtMobile.Text;
            txtMobile.Leave   += (s, args) => txtMobile.Text = txtMobile.Text == "" ? "Mobile Or Email" : txtMobile.Text;
            txtPassword.Enter += (s, args) => {
                if (txtPassword.Text == "New Password")
                {
                    txtPassword.Text         = "";
                    txtPassword.PasswordChar = '*';
                }
            };
            txtPassword.Leave += (s, args) => {
                if (txtPassword.Text == "")
                {
                    txtPassword.Text         = "New Password";
                    txtPassword.PasswordChar = '\0';
                }
            };

            MyTableLayoutPanel namePanel = new MyTableLayoutPanel(1, 2, DockStyle.Fill, new Padding(0, 5, 0, 5));

            namePanel.AutoSize = true;
            namePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            namePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            namePanel.Controls.Add(txtName, 0, 0);
            namePanel.Controls.Add(txtSurName, 1, 0);

            bottomRightPanel.Controls.Add(namePanel, 0, 2);
            bottomRightPanel.Controls.Add(txtMobile, 0, 3);
            bottomRightPanel.Controls.Add(txtPassword, 0, 4);

            GroupBox birthdayBox = new GroupBox()
            {
                Text     = "Birthday",
                Dock     = DockStyle.Fill,
                AutoSize = true,
                Padding  = new Padding(10)
            };

            dobPicker = new DateTimePicker()
            {
                Dock = DockStyle.Top
            };

            MyTableLayoutPanel radioButtonContainer = new MyTableLayoutPanel(1, 2, DockStyle.Fill);

            radioButtonContainer.AutoSize = true;
            radioButtonContainer.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            radioButtonContainer.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));

            male = new RadioButton()
            {
                Text    = "Male",
                Checked = true
            };
            female = new RadioButton()
            {
                Text = "Female"
            };

            radioButtonContainer.Controls.Add(male, 0, 0);
            radioButtonContainer.Controls.Add(female, 1, 0);

            birthdayBox.Controls.Add(dobPicker);

            bottomRightPanel.Controls.Add(birthdayBox, 0, 5);
            bottomRightPanel.Controls.Add(radioButtonContainer, 0, 6);

            bottomRightPanel.Controls.Add(new Label()
            {
                Text     = "By clicking Sign Up, you agree to our Terms, Data Policy and\nCookie Policy. You may receive SMS notifications from us and\ncan opt out at any time.",
                Font     = new Font("Helvetica", 8),
                AutoSize = true
            }, 0, 7);

            Button btnSignUp = new Button()
            {
                Text      = "Sign Up",
                Font      = new Font("Helvetica", 12, FontStyle.Bold),
                AutoSize  = true,
                ForeColor = Color.White,
                BackColor = System.Drawing.Color.FromArgb(95, 155, 76),
                Padding   = new Padding(15, 10, 15, 10)
            };

            bottomRightPanel.Controls.Add(btnSignUp, 0, 8);
            bottomPanel.Controls.Add(bottomLeftPanel, 0, 0);
            bottomPanel.Controls.Add(bottomRightPanel, 1, 0);
            mainPanel.Controls.Add(topPanel, 0, 0);
            mainPanel.Controls.Add(bottomPanel, 0, 1);

            this.Controls.Add(mainPanel);

            btnSignUp.Click += BtnSignUp_Click;
        }