Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <TextBox Height="38" TextWrapping="Wrap" VerticalAlignment="Top"
- Margin="16,23,0,0" HorizontalAlignment="Left" Width="226"
- FontSize="20" Background="Black" BorderThickness="2" Name="tb"
- Text="" KeyUp="KeyDownHandler">
- private void KeyDownHandler(object sender, KeyRoutedEventArgs e)
- {
- if (e.Key == Windows.System.VirtualKey.Enter)
- {
- result();
- }
- }
- private void result()
- {
- String op;
- int iOp = 0;
- if (tb.Text.Contains("+"))
- {
- iOp = tb.Text.IndexOf("+");
- }
- else if (tb.Text.Contains("-"))
- {
- iOp = tb.Text.IndexOf("-");
- }
- else if (tb.Text.Contains("*"))
- {
- iOp = tb.Text.IndexOf("*");
- }
- else if (tb.Text.Contains("/"))
- {
- iOp = tb.Text.IndexOf("/");
- }
- else
- {
- //error
- }
- op = tb.Text.Substring(iOp, 1);
- double num1 = Convert.ToDouble(tb.Text.Substring(0, iOp));
- double num2 = Convert.ToDouble(tb.Text.Substring(iOp + 1, tb.Text.Length - iOp - 2));
- if (op == "+")
- {
- tb.Text = Convert.ToString(num1 + num2);
- }
- else if (op == "-")
- {
- tb.Text = Convert.ToString(num1 - num2);
- }
- else if (op == "*")
- {
- tb.Text = Convert.ToString(num1 * num2);
- }
- else if (op == "/")
- {
- tb.Text = Convert.ToString(num1 / num2);
- }
- }
- double num2 = Convert.ToDouble(tb.Text.Substring(iOp + 1, tb.Text.Length - iOp - 2));
- double num2 = Convert.ToDouble(tb.Text.Substring(iOp + 1, tb.Text.Length - iOp - 1));
Add Comment
Please, Sign In to add comment