3
4
5 resultTextBlock.Text = result.ToString();
6
7 float v1 = float.Parse(firstNumberTextBox.Text);
8 float v1 = 0; if (!int.TryParse(firstNumberTextBox.Text, out v1)) { // Invalid text in textbox }
9
10 float v1 = 0; if (!float.TryParse(firstNumberTextBox.Text, out v1)) { firstNumberTextBox.Foreground = new SolidColorBrush(Colors.Red); return; }
11 float v1 = 0; if (!float.TryParse(firstNumberTextBox.Text, out v1)) { firstNumberTextBox.Foreground = new SolidColorBrush(Colors.Red); return; }
12
13 private SolidColorBrush errorBrush = new SolidColorBrush(Colors.Red); private Brush correctBrush = null;
14 private void calculateResult() { bool errorFound = false; if (correctBrush == null) correctBrush = firstNumberTextBox.Foreground; // Rest of method goes here }
15 private void calculateResult() { // Sort out brushes if (!float.TryParse(firstNumberTextBox.Text, out v1)) { firstNumberTextBox.Foreground = errorBrush; errorFound = true; } else { firstNumberTextBox.Foreground = correctBrush; } }
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 72
33
34 // Make a new input scope InputScope digitScope = new InputScope(); // Make a new input scope name InputScopeName digits = new InputScopeName(); // Set the new name to Digits digits.NameValue = InputScopeNameValue.Digits; // Add the name to the new scope digitScope.Names.Add(digits); // Set the scope of the textbox to the new scope firstNumberTextBox.InputScope = digitScope;
35
36
37 MessageBox.Show("Invalid Input" + System.Environment.NewLine + "Please re-enter");
38 if (MessageBox.Show("Do you really want to do this?", "Scary Thing", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { // do scary thing here } else { // do something else }
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57