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


    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;
    
            }
    
    
    
        }
    }
    

      

      

  • 相关阅读:
    npm使用淘宝镜像源
    MapReduce任务执行源码分析
    spark.sql.shuffle.partitions到底影响什么
    hdfs的写入数据流程及异常情况分析
    面试题
    HDFS的双缓冲机制详解
    rpm包无法卸载
    hive建表支持的文件类型与压缩格式
    centos6中同时安装python3.7与python2.6
    linux centos6.x安装mysql5.6.33版本
  • 原文地址:https://www.cnblogs.com/ruingking/p/5187529.html
Copyright © 2020-2023  润新知