You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you're using C#, be sure you put the code after the opening curly brace and just after the class declaration (`public partial class Form1 : Form`). If you're using Visual Basic, put the code right after the class declaration (`Public Class Form1`).
65
63
66
64
You can use list objects to keep track of different types of items.
Copy file name to clipboardExpand all lines: docs/get-started/csharp/tutorial-windows-forms-math-quiz-add-math-problems.md
+6-8Lines changed: 6 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ ms.custom: vs-acquisition
5
5
dev_langs:
6
6
- "CSharp"
7
7
- "VB"
8
-
ms.date: 03/15/2023
8
+
ms.date: 10/18/2024
9
9
ms.topic: tutorial
10
10
author: anandmeg
11
11
ms.author: meghaanand
@@ -37,7 +37,7 @@ This tutorial builds on a previous tutorial, [Create a math quiz WinForms app](t
37
37
38
38
1. On the menu bar, select **View** > **Code**. *Form1.cs* or *Form1.vb* appears, depending on the programming language that you're using, so that you can view the code behind the form.
39
39
40
-
1. Create a <xref:System.Random> object by adding a `new` statement near the top of the code.
40
+
1. Create a <xref:System.Random> object by adding a `new` statement near the top of the code in *Form1.cs* or *Form1.vb*.
You can use `new` statements like this one to create buttons, labels, panels, OpenFileDialogs, ColorDialogs, SoundPlayers, Randoms, and even forms. These items are called *objects*.
52
50
53
51
When you run your program, the form is started. The code behind it creates a Random object and names it **randomizer**.
54
52
55
53
Your quiz needs variables to store the random numbers that it creates for each problem. Before using variables, you declare them, which means listing their names and data types.
56
54
57
-
1. Add two integer variables to the form, and name them **addend1** and **addend2**.
55
+
1. Add two integer variables to the form, and name them **addend1** and **addend2** in *Form1.cs* or *Form1.vb*.
58
56
59
57
> [!NOTE]
60
58
> An integer variable is known as an *int* in C# or an *Integer* in Visual Basic. This kind of variable stores a positive or negative number from -2147483648 through 2147483647 and can store only whole numbers, not decimals.
@@ -68,7 +66,7 @@ This tutorial builds on a previous tutorial, [Create a math quiz WinForms app](t
1. Add a method that's named `StartTheQuiz()`. This method uses the Random object's <xref:System.Random.Next> method to generate random numbers for the labels. `StartTheQuiz()` will eventually fill in all the problems and then start the timer, so add this information to the summary comment. The function should look like the following code.
69
+
1. Add a method that's named `StartTheQuiz()`*Form1.cs* or *Form1.vb*. This method uses the Random object's <xref:System.Random.Next> method to generate random numbers for the labels. `StartTheQuiz()` will eventually fill in all the problems and then start the timer, so add this information to the summary comment. The function should look like the following code.
@@ -94,7 +92,7 @@ This tutorial builds on a previous tutorial, [Create a math quiz WinForms app](t
94
92
95
93
The next step is to declare variables and provide random values for the other math problems.
96
94
97
-
1. Add integer variables for the remaining math problems to your form, after the addition problem variables. The code should look like the following sample.
95
+
1. Add integer variables for the remaining math problems to your form, after the addition problem variables. The code in *Form1.cs* or *Form1.vb*should look like the following sample.
1. Modify the `StartTheQuiz()` method by adding the following code, starting with the "Fill in the subtraction problem" comment.
104
+
1. Modify the `StartTheQuiz()` method in *Form1.cs* or *Form1.vb*by adding the following code, starting with the "Fill in the subtraction problem" comment.
2. In **Windows Forms Designer**, move a <xref:System.Windows.Forms.Timer> control from the **Components** category of the **Toolbox** to your form. The control appears in the gray area at the bottom of the design window.
48
46
49
47
3. On the form, select the **timer1** icon that you just added, and set its **Interval** property to **1000**. Because this interval is in milliseconds, a value of 1000 causes the timer to raise a <xref:System.Windows.Forms.Timer.Tick> event every second.
- The first line declares the method. It includes a parameter that's named `sender`. In C#, the parameter is `object sender`. In Visual Basic, it's `sender As System.Object`. This parameter refers to the object whose event is firing, which is known as the sender. In this case, the sender object is the NumericUpDown control.
0 commit comments