-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFig-13.11 - ListBoxTest.cs
More file actions
132 lines (109 loc) · 3.35 KB
/
Copy pathFig-13.11 - ListBoxTest.cs
File metadata and controls
132 lines (109 loc) · 3.35 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Fig 13.11: ListBoxTest.cs
// Programa para adicionar, remover e limpar itens de caixa de lista.
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
partial class ListBoxTest : Form
{
private ListBox displayListBox;
private TextBox inputTextBox;
private Button addButton;
private Button removeButton;
private Button clearButton;
private Button exitButton;
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.displayListBox = new ListBox();
this.inputTextBox = new TextBox();
this.addButton = new Button();
this.removeButton = new Button();
this.clearButton = new Button();
this.exitButton = new Button();
// displayListBox.
this.displayListBox.Name = "displayListBox";
this.displayListBox.Location = new Point(10, 10);
this.displayListBox.Size = new Size(100, 150);
// inputTextBox.
this.inputTextBox.Name = "inputTextBox";
this.inputTextBox.Text = "";
this.inputTextBox.Location = new Point(120, 10);
this.inputTextBox.Size = new Size(100, 30);
// addButton.
this.addButton.Name = "addButton";
this.addButton.Text = "Add";
this.addButton.Location = new Point(120, 40);
this.addButton.Size = new Size(100, 30);
this.addButton.Click += new EventHandler(this.addButton_Click);
// removeButton.
this.removeButton.Name = "removeButton";
this.removeButton.Text = "Remove";
this.removeButton.Location = new Point(120, 80);
this.removeButton.Size = new Size(100, 30);
this.removeButton.Click += new EventHandler(this.removeButton_Click);
// clearButton.
this.clearButton.Name = "clearButton";
this.clearButton.Text = "Clear";
this.clearButton.Location = new Point(120, 120);
this.clearButton.Size = new Size(100, 30);
this.clearButton.Click += new EventHandler(this.clearButton_Click);
// exitButton.
this.exitButton.Name = "exitButton";
this.exitButton.Text = "Exit";
this.exitButton.Location = new Point(120, 160);
this.exitButton.Size = new Size(100, 30);
this.exitButton.Click += new EventHandler(this.exitButton_Click);
// ListBoxTest.
this.Controls.AddRange(new Control[]{
this.displayListBox, this.inputTextBox,
this.addButton, this.removeButton,
this.clearButton, this.exitButton
});
this.Name = "ListBoxTest";
this.Text = "ListBoxTest";
this.AutoScaleMode = AutoScaleMode.Font;
this.AutoSize = true;
this.ResumeLayout(false);
}
#endregion
private void addButton_Click(object sender, EventArgs e)
{
if (inputTextBox.Text.Length > 0)
{
displayListBox.Items.Add(inputTextBox.Text);
inputTextBox.Clear();
inputTextBox.Focus();
}
}
private void removeButton_Click(object sender, EventArgs e)
{
if (displayListBox.SelectedIndex != -1)
displayListBox.Items.RemoveAt(displayListBox.SelectedIndex);
}
private void clearButton_Click(object sender, EventArgs e)
{ displayListBox.Items.Clear(); }
private void exitButton_Click(object sender, EventArgs e)
{ Application.Exit(); }
}
partial class ListBoxTest
{
private Container? components = null;
public ListBoxTest()
{ 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 ListBoxTest());
}
}