回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,141 +1,71 @@
|
|
1
1
|
YAmaGNZさんの言っていることをコードにしただけですが^^;
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
```
|
3
|
+
```cs
|
6
|
-
|
7
4
|
using System;
|
8
|
-
|
9
5
|
using System.Linq;
|
10
|
-
|
11
6
|
using System.Windows.Forms;
|
12
7
|
|
13
|
-
|
14
|
-
|
15
8
|
namespace Questions269084
|
16
|
-
|
17
9
|
{
|
18
|
-
|
19
10
|
public partial class Form1 : Form
|
20
|
-
|
21
11
|
{
|
22
|
-
|
23
12
|
private readonly ListBox listBox;
|
24
|
-
|
25
13
|
private readonly TextBox textBox;
|
26
14
|
|
27
|
-
|
28
|
-
|
29
15
|
public Form1()
|
30
|
-
|
31
16
|
{
|
32
|
-
|
33
17
|
InitializeComponent();
|
34
18
|
|
35
|
-
|
36
|
-
|
37
19
|
textBox = new TextBox
|
38
|
-
|
39
20
|
{
|
40
|
-
|
41
21
|
Dock = DockStyle.Fill,
|
42
|
-
|
43
22
|
Multiline = true,
|
44
|
-
|
45
23
|
};
|
46
|
-
|
47
24
|
Controls.Add(textBox);
|
48
25
|
|
49
|
-
|
50
|
-
|
51
26
|
listBox = new ListBox
|
52
|
-
|
53
27
|
{
|
54
|
-
|
55
28
|
Dock = DockStyle.Left,
|
56
|
-
|
57
29
|
SelectionMode = SelectionMode.MultiSimple,
|
58
|
-
|
59
30
|
Width = 50,
|
60
|
-
|
61
31
|
};
|
62
|
-
|
63
32
|
listBox.Items.AddRange(new string[] { "A", "B", "C", "D", "E", "A", "A", });
|
64
|
-
|
65
33
|
listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged;
|
66
|
-
|
67
34
|
Controls.Add(listBox);
|
68
|
-
|
69
35
|
}
|
70
36
|
|
71
|
-
|
72
|
-
|
73
37
|
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
|
74
|
-
|
75
38
|
{
|
76
|
-
|
77
39
|
var text = "選択された\r\n";
|
78
|
-
|
79
40
|
foreach(var item in listBox.SelectedItems)
|
80
|
-
|
81
41
|
{
|
82
|
-
|
83
42
|
text += item + "\r\n";
|
84
|
-
|
85
43
|
}
|
86
44
|
|
87
|
-
|
88
|
-
|
89
45
|
text += "選択されていない\r\n";
|
90
|
-
|
91
46
|
for(var i = 0; i < listBox.Items.Count; i++)
|
92
|
-
|
93
47
|
{
|
94
|
-
|
95
48
|
if(!listBox.GetSelected(i))
|
96
|
-
|
97
49
|
{
|
98
|
-
|
99
50
|
text += listBox.Items[i] + "\r\n";
|
100
|
-
|
101
51
|
}
|
102
|
-
|
103
52
|
}
|
104
53
|
|
105
|
-
|
106
|
-
|
107
54
|
textBox.Text = text;
|
108
|
-
|
109
55
|
}
|
110
56
|
|
111
|
-
|
112
|
-
|
113
57
|
// 大体同じ
|
114
|
-
|
115
58
|
//private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
|
116
|
-
|
117
59
|
//{
|
118
|
-
|
119
60
|
// var text = "選択された\r\n";
|
120
|
-
|
121
61
|
// text += string.Join("\r\n", listBox.SelectedItems.Cast<object>());
|
122
62
|
|
123
|
-
|
124
|
-
|
125
63
|
// text += "\r\n選択されていない\r\n";
|
126
|
-
|
127
64
|
// var unSelected = listBox.Items.Cast<object>().Where((x, i) => !listBox.GetSelected(i));
|
128
|
-
|
129
65
|
// text += string.Join("\r\n", unSelected);
|
130
66
|
|
131
|
-
|
132
|
-
|
133
67
|
// textBox.Text = text;
|
134
|
-
|
135
68
|
//}
|
136
|
-
|
137
69
|
}
|
138
|
-
|
139
70
|
}
|
140
|
-
|
141
71
|
```
|