如何在C#中为计算器编写Windows窗体中的加号,减法,乘法和除法按钮? [英] How do I code the plus, subtraction, multiplication and division buttons in a windows form for a calculator in C#?

查看:720
本文介绍了如何在C#中为计算器编写Windows窗体中的加号,减法,乘法和除法按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编码的新手,想知道我应该使用哪些代码才能让计算器中的操作按钮正常工作。



我想要做的就是将正确的代码添加到我的加号按钮,依此类推。

我尝试了很多代码我在网上找到但似乎总是出现某种错误。



我尝试了什么:



网上很多例子,他们不可能都是错的我显然没有做正确的事。

解决方案

你可以看看这个第1步:创建Windows窗体应用程序项目 [ ^ ]特别是步骤5,6 ..有很多网上的其他开始winforms文章 - 让谷歌成为你的朋友 - 我说这不是一个痛苦,但图片胜过千言万语(试图描述'从工具栏拖动一个按钮到一个表格并挂钩它的事件'sux in words) - on你已经完成了几次,然后它是什么控制做什么的问题



提示 - 在一块上绘制/勾画'形式'纸张 - 标签,文本框(从中获取信息和(可以)向用户显示信息)和按钮 - 将标签,文本框,按钮命名为适当的 - 例如,带有+号的按钮在它上面可能是'button_add' - 主显示的文本框可能是'textbox_results' - 这意味着当你在按钮的处理程序中时,你知道计算的结果会被写入textbox_results。文本

I'm new to coding and would like to know what code I should use in order to have the operations buttons in my calculator working.

All I want to do is to add the correct code to my plus button, and so on.
I have tried many codes that I have found on the net but there always seem to be some sort of error.

What I have tried:

Many examples on the net, they can't all be wrong I'm obviously not doing something correctly.

解决方案

you could have a look at this Step 1: Create a Windows Forms Application Project[^] particularly steps 5,6.. there are plenty of other 'beginning winforms' articles on the web - let google be your friend - I say that not to be a pain, but pictures are worth a thousand words (trying to describe 'dragging a button from the toolbar onto a form and hooking up its event' sux in words) - once you've done it a few times, then its a matter of what control(s) do what

hint - draw/sketch the 'form' on a piece of paper - 'labels', textboxes (where you get information from and (can) display information back to your user), and buttons - name the labels, textboxes, buttons something appropriate - for example, a button with a '+' sign on it might be 'button_add' - a textbox for your main display may be 'textbox_results' - that means when you're in the 'handler' for your button(s), you know the result of the calculation gets written to textbox_results.Text


这篇关于如何在C#中为计算器编写Windows窗体中的加号,减法,乘法和除法按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆