美文网首页C# .NET
SunnyUI 入门教程

SunnyUI 入门教程

作者: 赌二八定律 | 来源:发表于2021-04-26 16:38 被阅读0次
    Visual Studio 安装

    点击修改按钮
    创建项目-使用SunnyUI引用

    引用 SunnyUI



    下载SunnyUI源代码
    打开源代码项目
    using Sunny.UI;
    
    namespace SunnyUITest
    {
    
        public partial class Form1 : UIForm
        {
            public Form1()
            {
                InitializeComponent();
            }
            /// <summary>
            /// 准备字符
            /// </summary>
            string strA = "";
    
            /// <summary>
            /// 操作字符
            /// </summary>
            string strB = "";
    
            /// <summary>
            /// 算法 1 表示加法---2:表示减法--3:表示乘法--4:除法
            /// </summary>
            public int algorithm = 0;
    
    
            /// <summary>
            /// 添加计算器字符
            /// </summary>
            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");
            }
            /// <summary>
            /// 加法
            /// </summary>
            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;
            }
            /// <summary>
            /// 减法
            /// </summary>
            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;
            }
            /// <summary>
            /// 乘法
            /// </summary>
            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;
            }
            /// <summary>
            /// 除法
            /// </summary>
            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)
            {
    
            }
            /// <summary>
            /// 等于
            /// </summary>
            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 入门教程

        本文链接:https://www.haomeiwen.com/subject/kicjrltx.html