zoukankan      html  css  js  c++  java
  • 计算器的简单编写,熟悉访问器,重载

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

      

      

  • 相关阅读:
    手机号码正则表达式
    POJ 3233 Matrix Power Series 矩阵快速幂
    UVA 11468
    UVA 1449
    HDU 2896 病毒侵袭 AC自动机
    HDU 3065 病毒侵袭持续中 AC自动机
    HDU 2222 Keywords Search AC自动机
    POJ 3461 Oulipo KMP模板题
    POJ 1226 Substrings KMP
    UVA 1455 Kingdom 线段树+并查集
  • 原文地址:https://www.cnblogs.com/ruingking/p/5187529.html
Copyright © 2011-2022 走看看