我如何创建销售税计算器?在c#中 [英] How do i create a sales tax calculator? in c#

查看:80
本文介绍了我如何创建销售税计算器?在c#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有一些简单的问题,一个是显示信息的标签,用户可以将信息输入到TextBox,虽然我希望程序显示它的是什么,用户无法输入任何信息?

我还必须显示税额(5.25%)和我必须支付的总金额。

我的计算按钮名为myCalcButton

我清除所有内容的清除按钮是myClearButton(我怎么写这个?基本上只是重新启动代码以便用户可以重新输入另一个金额)

用户输入金额的文本框(无需$)名为mySalesAmount

我的表单名为mySalesForm

一旦我记得显示答案的东西,一个将是myTaxAmount然后myTotalAmount



围绕这个任务的整个想法是学习计算,虽然这只是我的第二次任务,但我需要一些。如果您决定写出我需要的行,请彻底解释您决定使用该行代码的方式和原因。我真的想学习,虽然我在网上上课时犯了错误



我尝试了什么:



现在我已经浏览了Visual Studio 2012 Express(这是本课程所必需的),以了解我对GUI的需求。

我试图观看建议视频虽然480x480质量只是几乎不可能。

Alright a few quick questions, one being what is the label to display information, A user can input info into a TextBox though what is the one where I want my program to display it and the user cannot enter any info into it?
I also have to display the Tax Amount ( 5.25%) and the Total amount I have to pay.
The Calculate button I have is named myCalcButton
My Clear button to clear everything is myClearButton ( How would I write this also? To basically just almost restart the code so a user can re-enter another amount )
The Text box for users to enter an amount of money in ( No $ needed ) is named mySalesAmount
My form is named mySalesForm
Once I remember the thing to display the answer, the one will be myTaxAmount then myTotalAmount

The whole idea around this assignment is to learn calculations, Though this only being my second assignment I need some. If you decide to write out the lines I need, please thoroughly explain how and why you decided to use that line of code. I truly want to learn though I made a mistake taking the class online

What I have tried:

Right now I have looked through Visual Studio 2012 Express ( This is required for the course ) to find out what I need for the GUI.
I attempted to watch the suggested video though 480x480 quality just makes it almost not possible.

推荐答案

needed)被命名为mySalesAmount

我的表单名为mySalesForm

一旦我记得显示答案的东西,一个将是myTaxAmount然后myTotalAmount



围绕这个任务的整个想法是学习计算,虽然这个只是我的第二次任务,我需要一些。如果您决定写出我需要的行,请彻底解释您决定使用该行代码的方式和原因。我真的想学习,虽然我在网上上课时犯了错误



我尝试了什么:



现在我已经浏览了Visual Studio 2012 Express(这是本课程所必需的),以了解我对GUI的需求。

我试图观看建议视频虽然480x480质量只是让它几乎不可能。
needed ) is named mySalesAmount
My form is named mySalesForm
Once I remember the thing to display the answer, the one will be myTaxAmount then myTotalAmount

The whole idea around this assignment is to learn calculations, Though this only being my second assignment I need some. If you decide to write out the lines I need, please thoroughly explain how and why you decided to use that line of code. I truly want to learn though I made a mistake taking the class online

What I have tried:

Right now I have looked through Visual Studio 2012 Express ( This is required for the course ) to find out what I need for the GUI.
I attempted to watch the suggested video though 480x480 quality just makes it almost not possible.


哎呀,不要担心跟随人们的代码 - 没有人会为你做功课! (如果您首先学习控制台编程,如果重点是'计算',那么你的生活会更容易)



但是这里有一些关于开始的想法 - 你可能需要google for更多的解释,这是我的头脑,我没有VS开放 - 我认为如果你从来没有碰过gui这是一项艰巨的任务,但是,嘿,有谷歌[见本帖的底部]



1)启动Visual Studio

2)创建一个新的c#Winform项目,命名它[有用的东西 - 可能是作业名称或者'TaxCalculator']

3)如果项目浏览器中没有选择'Form1',请选择'Form1' - 右键单击​​它,将其重命名为mySalesForm

4)你需要的一些标签&表格上的文本框,这样你就有了



标签,一些空格,文本框



所以,看看在所有输入和输出中,将标签控件拖到窗体上,例如将其文本设置为Sales Amount,然后将TextBox向下拖动到右侧,将TextBox重命名为mySalesAmount



重复所有输入和输出,排列它们......



对于受保护文本框,您需要设置它的'ReadOnly'属性为'true' - 你通常会在'Form Load事件'中执行此操作,请参阅第7点



TextBoxes btw,可以输入或输出



5)你需要在表格上有两个按钮,从控件调色板拖动它们并定位它们,将一个重命名为myCalcButton,另一个重命名为myClearButton,设置文本为计算或清除的相应框



6)您需要将每个按钮与事件处理程序/过程相关联 - 这很棘手o以非可视方式解释,所以你可能需要找到一个更好的参考..本质上,你选择按钮,点击属性窗口顶部的'events'部分(我的属性窗口通常在右边) VS屏幕的手边)事件应该是'闪电螺栓',向下滚动'Click'事件,并将其设置为例如onMyClearButton_Clicked - VS环境将为每个添加空白程序代码



7)如果您可以通过6(两次,每个按钮一次),并且无法找到mySalesForm'加载'过程/事件处理程序,请选择表单本身,并且除了你正在寻找'加载'或'onLoad'事件之外,你可以在这里做一些事情,例如设置myXYZTextBox.ReadOnly = true;保护文本框



8)所以,然后你填写(例如)onMyCalcButton_Clicked事件处理程序中的代码 - 你需要做的事情就像'



8a)读取文本框的值... mySomeThingTextBox.Text - 存储用户输入内容的数据类型是什么 - 如果你不知道,看看8d



8b)检查价值是否为空



8c)将值转换为适合您计算的数据类型,或者如果输入的值是b / s,则以某种方式向用户发出信号



8d)将计算值写回文本框mySomeThingOtherTextBox.Text = ???? - 请注意,你可能会得到一个'数字类型'的结果,TextBoxes是Text又叫'String'类型,你需要关于格式化
heck, dont be worried about following people's code - no-one is going to do your homework for you ! (and your life would be easier if you learnt console programming first if the focus is 'calculations')

but here's some thoughts on starting - you may need to google for more explanation, this is off-the-top-of-my-head, I dont have VS open - I think its a daunting task if you've never touched a gui, but hey, there's google [see bottom of this post]

1) fire up Visual Studio
2) create a new c# Winform project, naming it [something useful - could be the assignment name or 'TaxCalculator']
3) Select 'Form1' if its not already selected, in the project explorer - right click it, rename it to mySalesForm
4) you need a number of labels & textboxes on the form, so that you have

label, some spaces, textbox

so, look at all your inputs and outputs, drag a label control onto the form, set its text to 'Sales Amount' for example, then drag down a TextBox to the right of it, rename the TextBox to 'mySalesAmount'

repeat for all inputs and outputs, line them up ...

For a 'protected' Textbox, you need to set its 'ReadOnly' property to 'true' - you'd usually do this on the 'Form Load event' see point 7

TextBoxes btw, can be input or output

5) you need two button's on the form, drag them from the controls palette and position them, rename one to myCalcButton, the other to myClearButton, set the text for the appropriate box to 'Calculate' or 'Clear'

6) you need to associate each button with an event handler/procedure - this is tricky to explain in a non visual way, so again, you might need to find a better reference .. essentially, you select the button, click the 'events' section at the top of the properties window (my property window is usually on the right hand side of the VS screen) events should be the 'lightening bolt', scroll down for the 'Click' event, and set that to for example onMyClearButton_Clicked - the VS environment will add the blank procedure code for each of these

7) if you can get your way through 6 (twice, once for each button), and cant find a mySalesForm 'Load' procedure/event handler, select the form itself, and to the same sort of thing as per (6), except you're looking for the 'Load' or 'onLoad' event - this is where you'll do things like set myXYZTextBox.ReadOnly = true; to protect the textbox

8) So, you then fill out the code in the (for example) onMyCalcButton_Clicked Event Handler - you will need to do things 'like'

8a) read the value of a textbox ... mySomeThingTextBox.Text - what is the data type going to be to store what the user has entered - if you dont know, look at 8d

8b) check if the value is empty

8c) convert the value to an appropriate data type for your calculation or signal the user somehow if the value they entered is b/s

8d) write values of calculations back to text boxes mySomeThingOtherTextBox.Text = ???? - mind you, you'll likely have the result in a 'numeric type', and TextBoxes are Text aka 'String' type,and you'll need to thing about formatting the


值的事情适当的 - 小数点+/-货币符号等



9)从(8)开始,你的'清除'按钮可能会设置myTextBox.Text =;对于所有相关的文本框 - 所以你在onMyClearButton_Clicked程序/事件处理程序中填写所有这些



你真的需要一个体面的GUI教科书 - 这些说明是粗糙的作为胆量对不起 - 这些链接可能会有所帮助



http://cplus.about.com/od/learnc/ss/random.htm#step2 [ ^ ]



第1步:创建Windows窗体应用程序项目 [ ^ ]



使用Visual C#来开始使用Windows窗体Holowczak.com [ ^ ]
value appropriately - decimal points +/- currency symbols etc

9) following from (8), your 'Clear' button will likely set myTextBox.Text = ""; for all the relevant text boxes - so you fill all this out in the onMyClearButton_Clicked procedure/event handler

You really need a decent GUI textbook though - these instructions are as rough as guts sorry - these links may help

http://cplus.about.com/od/learnc/ss/random.htm#step2[^]

Step 1: Create a Windows Forms Application Project[^]

Getting Started with Windows Forms using Visual C# | Holowczak.com[^]


这篇关于我如何创建销售税计算器?在c#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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