• 计算器的简单编写,熟悉访问器,重载


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace 计算器
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void comboBox1_DrawItem(object sender, DrawItemEventArgs e) //修改combox 信息 中间显示
            {
                string s = this.comboBox1.Items[e.Index].ToString();
                SizeF ss = e.Graphics.MeasureString(s, e.Font);
    
                float l = (float)(e.Bounds.Width - ss.Width) / 2;
                if (l < 0) l = 0f;
                float t = (float)(e.Bounds.Height - ss.Height) / 2;
                if (t < 0) t = 0f;
                t = t + this.comboBox1.ItemHeight * e.Index;
                e.DrawBackground();
                e.DrawFocusRectangle();
                e.Graphics.DrawString(s, e.Font, new SolidBrush(e.ForeColor), l, t);
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                int str1 = Convert.ToInt32(textBox1.Text);
                int str2 = Convert.ToInt32(textBox2.Text);
    
    
    
                Jisuan jisuan = new Jisuan(Convert.ToInt32(str1), Convert.ToInt32(str2));
                switch (comboBox1.Text)
                {
    
                    case "+": label1.Text = jisuan.Add().ToString(); break;
    
    
    
                }
            }
        }
    }
















    类:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 计算器
    {
        public class Jisuan
        {
    
            public Jisuan(int str1, int str2)
            {
                this.Number1 = str1;
                this.Number2 = str2;
    
    
            }
    
    
    
    
            public int Number1
            {
    
                get ;
                set;
    
            }
    
    
            public int Number2
            {
    
                get;
                set;
    
            }
    
            public int Add()
            {
    
                return Number1 + Number2;
    
            }
    
    
    
        }
    }
    

      

      

  • 相关阅读:
    「板子」环形带限制的子段和
    【模版】拓扑排序
    【模板】点分治
    扬声大笑出门去,我辈岂是蓬蒿人
    JAVA JDK(3)—— jdk7特性
    电路原理 —— 三相电路(1.5)
    JAVA JDK(2)—— jdk6特性
    数据结构 —— 栈和队列
    电路原理(六) —— 正弦稳态电路分析(1)
    静电场(完) —— 静电场的环路定理 电势
  • 原文地址:https://www.cnblogs.com/ruingking/p/5187529.html
Copyright © 2020-2023  润新知