且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#中为计算器编写Windows窗体中的加号,减法,乘法和除法按钮?

更新时间:2023-09-04 17:12:04

你可以看看这个第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