Calculator (Windows programming)

Foreword

  While enjoying the convenience of managing blog (Feeling a little ugly blog) = V =, but still you want to get hold of their own server to record the life and learning, autonomy little higher, mainly put some projects can run their own written summary of their own things sink, later for others convenience point of view, on the server do not save money, and can white white prostitute prostitute, to the py py, it is not to buy it. ( `· Ω · ')

Problem Description

Design a fully functional, beautiful interface calculator application. Claim:

  • (1) The user can input operands by a mouse click button, text box, to achieve add, subtract, multiply, and the reciprocal of the four arithmetic operations like addition, inversion function. Layout required to achieve good results, by functional classification to simplify programming buttons.
  • (2) In addition to the mouse input, keyboard input, and which can achieve operations (i.e., via the keyboard to enter numbers and operators, to achieve the same effect with button clicks).
  • (3) and to achieve continuous fractional arithmetic operation;
  • (4) to achieve sqrt, sin and other scientific computing functions;
  • (5) implement additional functions such as parsing expression

Solutions

Many buttons are distinguished by different events

  Such as four arithmetic event DoudleClicked, and sqrt, x ^ 2,1 / x, sinx is SingleClicked, assigned to the same button a different incident, a high reusability of code, clear logic.

Use MSScriptControl to resolve interpretive expression

 SScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
 sc.Language = "JavaScript";
 textBox1.Text= sc.Eval(textBox2.Text.ToString()).ToString();

  Wherein textBox1.Text the result, TextBox2.Text is a string, such as 1 + 3 * 5-4 / 2 it can help directly required by the priority, and then count subtraction, so here is my code problems in dealing with the four operations, it will conflict if the process SingleClicked event. If you are interested, you can even continue to study the effect is as follows:

        = =

Attach Source Project Portal

Guess you like

Origin www.cnblogs.com/xxhao/p/12513369.html