Creating calculator application is very simple using Asp.Net.
Web form:
  1. <table>
  2. <tr>
  3. <td colspan="4">
  4. </td>
  5. </tr>
  6. <tr>
  7. <td colspan="4">
  8. <asp:TextBox ID="DisplayTextBox1" runat="server" Height="45px" Width="375px"
  9. TextMode="MultiLine" Font-Bold="True" Font-Size="X-Large" ReadOnly="True"></asp:TextBox>
  10. </td>
  11. </tr>
  12. <tr>
  13. <td colspan="4" height="30px">
  14. <asp:Label ID="Answer" runat="server" Font-Bold="True"
  15. Font-Size="X-Large"></asp:Label>
  16. </td>
  17. </tr>
  18. <tr>
  19. <td>
  20. <asp:Button ID="Button21" runat="server" Height="50px" Text="("
  21. Width="95px" onclick="Button21_Click" />
  22. </td>
  23. <td>
  24. <asp:Button ID="Button22" runat="server" Height="50px" Text=")"
  25. Width="95px" onclick="Button22_Click" />
  26. </td>
  27. <td>
  28. <asp:Button ID="Button24" runat="server" Height="50px" Text="DEL"
  29. Width="95px" onclick="Button24_Click" />
  30. </td>
  31. <td>
  32. <asp:Button ID="Button25" runat="server" Height="50px" Text="AC"
  33. Width="95px" onclick="Button25_Click" />
  34. </td>
  35. </tr>
  36. <tr>
  37. <td>
  38. <asp:Button ID="ButtonNumber7" runat="server" Height="50px" Text="7"
  39. Width="95px" onclick="ButtonNumber7_Click" />
  40. </td>
  41. <td>
  42. <asp:Button ID="ButtonNumber8" runat="server" Height="50px" Text="8"
  43. Width="95px" onclick="ButtonNumber8_Click" />
  44. </td>
  45. <td>
  46. <asp:Button ID="ButtonNumber9" runat="server" Height="50px" Text="9"
  47. Width="95px" onclick="ButtonNumber9_Click" />
  48. </td>
  49. <td>
  50. <asp:Button ID="ButtonNumberDevide" runat="server" Height="50px" Text="÷"
  51. Width="95px" ForeColor="Black"
  52. onclick="ButtonNumberDevide_Click" />
  53. </td>
  54. </tr>
  55. <tr>
  56. <td>
  57. <asp:Button ID="ButtonNumber4" runat="server" Height="50px" Text="4"
  58. Width="95px" onclick="ButtonNumber4_Click" />
  59. </td>
  60. <td>
  61. <asp:Button ID="ButtonNumber5" runat="server" Height="50px" Text="5"
  62. Width="95px" onclick="ButtonNumber5_Click" />
  63. </td>
  64. <td>
  65. <asp:Button ID="ButtonNumber6" runat="server" Height="50px" Text="6"
  66. Width="95px" onclick="ButtonNumber6_Click" />
  67. </td>
  68. <td>
  69. <asp:Button ID="ButtonNumberMulti" runat="server" Height="50px" Text="X"
  70. Width="95px" onclick="ButtonNumberMulti_Click" />
  71. </td>
  72. </tr>
  73. <tr>
  74. <td>
  75. <asp:Button ID="ButtonNumber1" runat="server" Height="50px" Text="1"
  76. Width="95px" onclick="ButtonNumber1_Click" />
  77. </td>
  78. <td>
  79. <asp:Button ID="ButtonNumber2" runat="server" Height="50px" Text="2"
  80. Width="95px" onclick="ButtonNumber2_Click" />
  81. </td>
  82. <td>
  83. <asp:Button ID="ButtonNumber3" runat="server" Height="50px" Text="3"
  84. Width="95px" ClientIDMode="AutoID" onclick="ButtonNumber3_Click" />
  85. </td>
  86. <td>
  87. <asp:Button ID="ButtonNumberMinus" runat="server" Height="50px" Text="_"
  88. Width="95px" onclick="ButtonNumberMinus_Click" />
  89. </td>
  90. </tr>
  91. <tr>
  92. <td>
  93. <asp:Button ID="ButtonNumber0" runat="server" Height="50px" Text="0"
  94. Width="95px" onclick="ButtonNumber0_Click" />
  95. </td>
  96. <td>
  97. <asp:Button ID="ButtonNumberdot" runat="server" Height="50px" Text="."
  98. Width="95px" onclick="ButtonNumberdot_Click" />
  99. </td>
  100. <td>
  101. <asp:Button ID="ButtonNumberEqual" runat="server" Height="50px" Text="="
  102. Width="95px" onclick="ButtonNumberEqual_Click" />
  103. </td>
  104. <td>
  105. <asp:Button ID="ButtonNumberPlus" runat="server" Height="50px" Text="+"
  106. Width="95px" onclick="ButtonNumberPlus_Click" />
  107. </td>
  108. </tr>
  109. </table>
C#:
Add the following namespace.
  1. using System.Data;
Add the following code inside the .cs page.
  1. protected void Button21_Click(object sender, EventArgs e)
  2. {
  3. DisplayTextBox1.Text = DisplayTextBox1.Text + "(";
  4. }
  5. protected void Button22_Click(object sender, EventArgs e)
  6. {
  7. DisplayTextBox1.Text = DisplayTextBox1.Text + ")";
  8. }
  9. protected void Button25_Click(object sender, EventArgs e)
  10. {
  11. DisplayTextBox1.Text = "";
  12. Answer.Text = "";
  13. }
  14. protected void Button24_Click(object sender, EventArgs e)
  15. {
  16. string DisplayText = DisplayTextBox1.Text;
  17. int LastIndex = DisplayText.Length;
  18. DisplayTextBox1.Text = DisplayTextBox1.Text.Remove(LastIndex - 1);
  19. }
  20. protected void ButtonNumberEqual_Click(object sender, EventArgs e)
  21. {
  22. try
  23. {
  24. string Input = DisplayTextBox1.Text;
  25. DataTable table = new DataTable();
  26. Object answer;
  27. answer = table.Compute(Input, null);
  28. Answer.Text = answer.ToString();
  29. }
  30. catch
  31. {
  32. Answer.Text = "ERROR :(";
  33. }
  34. }
Now run the program :)
calculator application jhg