-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFig-6.09 - RandomInt.cs
More file actions
83 lines (68 loc) · 1.76 KB
/
Copy pathFig-6.09 - RandomInt.cs
File metadata and controls
83 lines (68 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Fig. 6.9: RandomInt.cs
// Gerando valores inteiros aleatórios.
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
partial class RandomInt : Form
{
private Button showOutputButton;
private Label outputLabel;
private void InitializeComponent()
{
this.showOutputButton = new Button();
this.outputLabel = new Label();
// showOutputButton.
this.showOutputButton.Name = "showOutputButton";
this.showOutputButton.Text = "Show Output";
this.showOutputButton.AutoSize = true;
this.showOutputButton.Location = new Point(10, 10);
this.showOutputButton.Click += new EventHandler(showOutputButton_Click);
// outputLabel.
this.outputLabel.Name = "outputLabel";
this.outputLabel.Text = "";
this.outputLabel.AutoSize = true;
this.outputLabel.Location = new Point(10, 40);
// RandomInt.
this.Controls.AddRange(new Control[]{
this.showOutputButton, this.outputLabel
});
this.Name = "RandomInt";
this.Text = "RandomInt";
this.AutoSize = true;
this.ResumeLayout(false);
}
private void showOutputButton_Click(object? sender, EventArgs e)
{
Random randomInteger = new Random();
outputLabel.Text = "";
for (int counter = 1; counter <= 20; counter++)
{
int nextValue = randomInteger.Next(1, 7);
outputLabel.Text += nextValue + " ";
if (counter % 5 == 0)
outputLabel.Text += "\n";
}
}
}
partial class RandomInt
{
private Container? components = null;
public RandomInt()
{ InitializeComponent(); }
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{ components.Dispose(); }
base.Dispose(disposing);
}
}
static class Program
{
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new RandomInt());
}
}