Download presentation
Presentation is loading. Please wait.
Published byNickolas Eaton Modified over 9 years ago
3
3
4
4
5
5 resultTextBlock.Text = result.ToString();
6
6
7
7 float v1 = float.Parse(firstNumberTextBox.Text);
8
8 float v1 = 0; if (!int.TryParse(firstNumberTextBox.Text, out v1)) { // Invalid text in textbox }
9
9
10
10 float v1 = 0; if (!float.TryParse(firstNumberTextBox.Text, out v1)) { firstNumberTextBox.Foreground = new SolidColorBrush(Colors.Red); return; }
11
11 float v1 = 0; if (!float.TryParse(firstNumberTextBox.Text, out v1)) { firstNumberTextBox.Foreground = new SolidColorBrush(Colors.Red); return; }
12
12
13
13 private SolidColorBrush errorBrush = new SolidColorBrush(Colors.Red); private Brush correctBrush = null;
14
14 private void calculateResult() { bool errorFound = false; if (correctBrush == null) correctBrush = firstNumberTextBox.Foreground; // Rest of method goes here }
15
15 private void calculateResult() { // Sort out brushes if (!float.TryParse(firstNumberTextBox.Text, out v1)) { firstNumberTextBox.Foreground = errorBrush; errorFound = true; } else { firstNumberTextBox.Foreground = correctBrush; } }
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32 72
33
33
34
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
35
36
36
37
37 MessageBox.Show("Invalid Input" + System.Environment.NewLine + "Please re-enter");
38
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
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
47
48
48
49
49
50
50
51
51
52
52
53
53
54
54
55
55
56
56
57
57
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.