C#计算器(组合框控件)

namespace WindowsFormsApplication5
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.textBox3 = new System.Windows.Forms.TextBox();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(255, 185);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(51, 75);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 21);
            this.textBox1.TabIndex = 2;
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(266, 74);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(100, 21);
            this.textBox2.TabIndex = 3;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(385, 77);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(41, 12);
            this.label1.TabIndex = 4;
            this.label1.Text = "label1";
            // 
            // textBox3
            // 
            this.textBox3.Location = new System.Drawing.Point(448, 75);
            this.textBox3.Name = "textBox3";
            this.textBox3.Size = new System.Drawing.Size(100, 21);
            this.textBox3.TabIndex = 5;
            // 
            // comboBox1
            // 
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Location = new System.Drawing.Point(184, 75);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(46, 20);
            this.comboBox1.TabIndex = 6;
           
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(607, 262);
            this.Controls.Add(this.comboBox1);
            this.Controls.Add(this.textBox3);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox textBox3;
        private System.Windows.Forms.ComboBox comboBox1;
    }
}


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 WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text = "=";
            button1.Text = "运算";
            comboBox1.Items.Add("+");
            comboBox1.Items.Add("-");
            comboBox1.Items.Add("*");
            comboBox1.Items.Add("/");
           
        }
        string text;
    
        private void button1_Click(object sender, EventArgs e)
        {
            switch (comboBox1.Text)
            {
                case "+":
                    text = (double.Parse(textBox1.Text) + double.Parse(textBox2.Text)).ToString();
                    break;
                case "-":
                    text = (double.Parse(textBox1.Text) - double.Parse(textBox2.Text)).ToString();
                    break;
                case "*":
                    text = (double.Parse(textBox1.Text) * double.Parse(textBox2.Text)).ToString();
                    break;
                case "/":
                    text = (double.Parse(textBox1.Text) / double.Parse(textBox2.Text)).ToString();
                    break;
                default:
                    break;
            }
            textBox3.Text = text;
        }
    }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、实验题目:计算器实验 二、实验目的: 1)熟悉.NET的编程方法,掌握项目的创建与使用及安装; 2)熟悉C#编程语言,字符串使用、自定义类、自定义类库等; 3)熟悉Windows应用程序类编程、事件驱动编程; 三、实验内容: 1)参照Windows提供的计算器工具,设计一个与之类似的程序;另外可参考运行效果下载(计算器Demo程序); 2)基本要求:实现“普通运算”功能,支持连续运算,如连续输入“2+3×5”后点击“等号”按钮进行运算其结果为25. 3)附加要求: A,支持“科学运算”功能,即输入表达式时遵循运算符号的优先原则,连续输入“2+3×5”后点击“等号”按钮进行运算其结果为17; B,支持数字键盘(小键盘)输入功能(焦点不在文本内时也支持键盘输入); 四、实验方法 经过用户的输入得到数学表达式后,可选择以下方法计算结果: 方法1)不定义"计算类",根据用户输入在程序直接计算出结果。 方法2)在项目设计一个计算类(CalculateClass),其包含“普通计算”和“科学计算”功能,即输入数学运算表达式字符串,返回计算结果。直接在项目调用该类,输出计算结果。 方法3)在解决方案增加一个类库(ClassLibrary)项目(在bin\debug下生成dll文件),其包含计算类(CalculateClass),该类包含两个方法(普通计算和科学计算),可以根据表达式计算结果。然后在计算器项目“引用”该类库的类,输出计算结果; 点评:方法1代码重用性差;方法2代码重用性好,在项目内可方便使用;方法3代码重用性较好,能在不同的项目内重用。 五、实验说明 1)认真分析总结每个“按钮”点击之后的动作(对应的代码); 默认的控件是Button按钮,其实可以用其他支持Click事件的控件替代也行,比如图片控件PictureBox; 2)代码的共享:如数字按钮可以共享一个事件代码; // 参考代码 private void button2_Click(object sender, EventArgs e) { Button objbutton = (Button)sender; label1.Text = "你按了第" + (sender as Button).Tag.ToString() + "个按钮"; } 3)考虑操作性或实用性,如支持退格键、异常输入处理等; 4)为突出实验重点,可以不考虑数制转换、复合运算、括号运算等功能; 5)支持数字小键盘输入时,留意理解窗口的KeyPreview属性,即是否窗口接收键盘事件。另外实现时会涉及到“焦点隐藏”问题,以及按钮的键盘事件等。 敲键盘时发生的事件当然是键盘事件,关键是“窗体”还是“控件”接收键盘事件。如果窗体的KeyPreview设为true,则敲键盘时发生的事件被窗体接收;否则就是控件接收键盘事件。 所谓“焦点隐藏” 是指界面上没有焦点,例如系统提供的计算器。方法一:界面上的控件不获取焦点或者没有焦点(如标签);方法二:将焦点藏在界面上不可见的控件上。 支持数字键盘输入的情形:当焦点在按钮1上时,按数字键2,其使用效果应相当于点击了按钮2。 6)键盘事件KeyPress和KeyDowne参数包括键盘码; private void KeyBoardForm_KeyPress(object sender, KeyPressEventArgs e) { //KeyPress 不能识别组合键 label1.Text = "你按的键是:" + e.KeyChar; } 7)“麻雀虽小,五脏俱全”,程序很容易出Bug,请认真调试; 8)要想达到界面有特点,不亚于在功能上下功夫。
目标检测(Object Detection)是计算机视觉领域的一个核心问题,其主要任务是找出图像所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问题,即定位出图像目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问题 目标检测涉及以下几个核心问题: 分类问题:判断图像的目标属于哪个类别。 定位问题:确定目标在图像的具体位置。 大小问题:目标可能具有不同的大小。 形状问题:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问题,将输入图像一次性划分为多个区域,直接在输出层预测边界和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值