SunnyUI 入门教程

Visual Studio 安装

点击修改按钮

创建项目-使用SunnyUI引用

引用 SunnyUI



下载SunnyUI源代码

打开源代码项目

using Sunny.UI;

namespace SunnyUITest
{

    public partial class Form1 : UIForm
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// 
        /// 准备字符
        /// 
        string strA = "";

        /// 
        /// 操作字符
        /// 
        string strB = "";

        /// 
        /// 算法 1 表示加法---2:表示减法--3:表示乘法--4:除法
        /// 
        public int algorithm = 0;


        /// 
        /// 添加计算器字符
        /// 
        public void AddString(string str)
        {
            this.uiTextBox1.Text = this.uiTextBox1.Text + str;
        }
        
        private void uiButton2_Click(object sender, System.EventArgs e)
        {
            AddString("1");
        }

        private void uiButton6_Click(object sender, System.EventArgs e)
        {
            AddString("2");
        }

        private void uiButton8_Click(object sender, System.EventArgs e)
        {
            AddString("3");
        }

        private void uiButton5_Click(object sender, System.EventArgs e)
        {
            AddString("4");
        }

        private void uiButton10_Click(object sender, System.EventArgs e)
        {
            AddString("5");
        }

        private void uiButton7_Click(object sender, System.EventArgs e)
        {
            AddString("6");
        }

        private void uiButton4_Click(object sender, System.EventArgs e)
        {
            AddString("7");
        }

        private void uiButton9_Click(object sender, System.EventArgs e)
        {
            AddString("8");
        }

        private void uiButton11_Click(object sender, System.EventArgs e)
        {
            AddString("9");
        }

        private void uiButton12_Click(object sender, System.EventArgs e)
        {
            AddString("0");
        }
        /// 
        /// 加法
        /// 
        private void uiButton14_Click(object sender, System.EventArgs e)
        {
            algorithm = 1;
            strA = this.uiTextBox1.Text;
            this.uiTextBox1.Text = this.uiTextBox1.Text + " + ";
            strB = this.uiTextBox1.Text;
        }
        /// 
        /// 减法
        /// 
        private void uiButton15_Click(object sender, System.EventArgs e)
        {
            algorithm = 2;
            strA = this.uiTextBox1.Text;
            this.uiTextBox1.Text = this.uiTextBox1.Text + " - ";
            strB = this.uiTextBox1.Text;
        }
        /// 
        /// 乘法
        /// 
        private void uiButton16_Click(object sender, System.EventArgs e)
        {
            algorithm = 3;
            strA = this.uiTextBox1.Text;
            this.uiTextBox1.Text = this.uiTextBox1.Text + " * ";
            strB = this.uiTextBox1.Text;
        }
        /// 
        /// 除法
        /// 
        private void uiButton17_Click(object sender, System.EventArgs e)
        {
            algorithm = 4;
            strA = this.uiTextBox1.Text;
            this.uiTextBox1.Text = this.uiTextBox1.Text + " / ";
            strB = this.uiTextBox1.Text;
        }

        private void uiButton13_Click(object sender, System.EventArgs e)
        {
            this.uiTextBox1.Clear();
        }

        private void uiButton3_Click(object sender, System.EventArgs e)
        {

        }
        /// 
        /// 等于
        /// 
        private void uiButton18_Click(object sender, System.EventArgs e)
        {
            if (algorithm == 1)
            {//加法
                int len = strB.Length;
                string strC = this.uiTextBox1.Text.Substring(len);
                this.uiTextBox1.Text = (int.Parse(strA) + int.Parse(strC)).ToString();
            }
            else if (algorithm == 2)
            {//减法
                int len = strB.Length;
                string strC = this.uiTextBox1.Text.Substring(len);
                this.uiTextBox1.Text = (int.Parse(strA) - int.Parse(strC)).ToString();
            }
            else if (algorithm == 3)
            {//乘法
                int len = strB.Length;
                string strC = this.uiTextBox1.Text.Substring(len);
                this.uiTextBox1.Text = (int.Parse(strA) * int.Parse(strC)).ToString();
            }
            else if (algorithm == 4)
            {//除法
                int len = strB.Length;
                string strC = this.uiTextBox1.Text.Substring(len);
                this.uiTextBox1.Text = (int.Parse(strA) / int.Parse(strC)).ToString();
            }
            else
            {
                ShowInfoDialog("算法有误");
            }
        }
    }
}

你可能感兴趣的:(SunnyUI 入门教程)