回答編集履歴
1
見直しキャンペーン中
answer
CHANGED
@@ -1,250 +1,244 @@
|
|
1
|
-
Zuishinさんの手順にそってざっと作ってみました。
|
2
|
-
大体のところはデザイナでできます。書いた部分はForm1.csとToDoItem.csです。
|
3
|
-
|
4
|
-
|
5
|
-
```
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
{
|
12
|
-
|
13
|
-
|
14
|
-
public
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
```
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
using System;
|
25
|
-
using System.
|
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
|
-
this.
|
118
|
-
this.
|
119
|
-
this.
|
120
|
-
this.
|
121
|
-
this.
|
122
|
-
|
123
|
-
|
124
|
-
this.
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
this.
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
this.dataGridView1.
|
135
|
-
this.dataGridView1.
|
136
|
-
this.dataGridView1.
|
137
|
-
this.
|
138
|
-
this.
|
139
|
-
this.
|
140
|
-
this.dataGridView1.
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
this.
|
145
|
-
this.
|
146
|
-
this.
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
this.Add.
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
this.
|
155
|
-
this.
|
156
|
-
this.
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
this.Delete.
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
this.
|
165
|
-
this.
|
166
|
-
this.
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
this.Save.
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
this.
|
175
|
-
this.
|
176
|
-
this.
|
177
|
-
|
178
|
-
//
|
179
|
-
//
|
180
|
-
|
181
|
-
this.
|
182
|
-
this.
|
183
|
-
this.
|
184
|
-
|
185
|
-
//
|
186
|
-
//
|
187
|
-
|
188
|
-
this.
|
189
|
-
this.
|
190
|
-
this.
|
191
|
-
|
192
|
-
//
|
193
|
-
//
|
194
|
-
|
195
|
-
this.
|
196
|
-
this.
|
197
|
-
this.
|
198
|
-
//
|
199
|
-
//
|
200
|
-
//
|
201
|
-
this.
|
202
|
-
this.
|
203
|
-
this.
|
204
|
-
|
205
|
-
//
|
206
|
-
//
|
207
|
-
|
208
|
-
this.
|
209
|
-
|
210
|
-
|
211
|
-
//
|
212
|
-
|
213
|
-
|
214
|
-
this.
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
this.
|
219
|
-
this.
|
220
|
-
this.
|
221
|
-
this.
|
222
|
-
this.
|
223
|
-
|
224
|
-
|
225
|
-
this.
|
226
|
-
this.
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
private System.Windows.Forms.
|
239
|
-
private System.Windows.Forms.
|
240
|
-
private System.Windows.Forms.
|
241
|
-
private System.Windows.Forms.
|
242
|
-
|
243
|
-
|
244
|
-
private System.Windows.Forms.BindingSource toDoItemBindingSource;
|
245
|
-
private System.Windows.Forms.DataGridViewCheckBoxColumn completedColumn;
|
246
|
-
private System.Windows.Forms.DataGridViewTextBoxColumn deadlineColumn;
|
247
|
-
private System.Windows.Forms.DataGridViewTextBoxColumn taskColumn;
|
248
|
-
}
|
249
|
-
}
|
1
|
+
Zuishinさんの手順にそってざっと作ってみました。
|
2
|
+
大体のところはデザイナでできます。書いた部分はForm1.csとToDoItem.csです。
|
3
|
+
|
4
|
+
|
5
|
+
```cs:ToDoItem.cs
|
6
|
+
using System;
|
7
|
+
|
8
|
+
namespace Questions245208
|
9
|
+
{
|
10
|
+
public class ToDoItem
|
11
|
+
{
|
12
|
+
public bool Completed { get; set; }
|
13
|
+
public DateTime Deadline { get; set; }
|
14
|
+
public string Task { get; set; }
|
15
|
+
}
|
16
|
+
}
|
17
|
+
```
|
18
|
+
|
19
|
+
```cs:Form1.cs
|
20
|
+
using System;
|
21
|
+
using System.Collections.Generic;
|
22
|
+
using System.IO;
|
23
|
+
using System.Runtime.Serialization;
|
24
|
+
using System.Windows.Forms;
|
25
|
+
using System.Xml;
|
26
|
+
|
27
|
+
namespace Questions245208
|
28
|
+
{
|
29
|
+
public partial class Form1 : Form
|
30
|
+
{
|
31
|
+
public Form1()
|
32
|
+
{
|
33
|
+
InitializeComponent();
|
34
|
+
|
35
|
+
if(File.Exists("todo.xml"))
|
36
|
+
{
|
37
|
+
using(var fs = new FileStream("todo.xml", FileMode.Open))
|
38
|
+
{
|
39
|
+
var serializer = new DataContractSerializer(typeof(List<ToDoItem>));
|
40
|
+
toDoItemBindingSource.DataSource = serializer.ReadObject(fs);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
private void Add_Click(object sender, EventArgs e)
|
46
|
+
{
|
47
|
+
var item = new ToDoItem
|
48
|
+
{
|
49
|
+
Task = textBox1.Text,
|
50
|
+
Deadline = dateTimePicker1.Value,
|
51
|
+
};
|
52
|
+
toDoItemBindingSource.Add(item);
|
53
|
+
}
|
54
|
+
|
55
|
+
private void Delete_Click(object sender, EventArgs e)
|
56
|
+
{
|
57
|
+
//toDoBindingSource.RemoveCurrent();
|
58
|
+
|
59
|
+
foreach(DataGridViewRow row in dataGridView1.SelectedRows)
|
60
|
+
{
|
61
|
+
if(!row.IsNewRow)
|
62
|
+
{
|
63
|
+
dataGridView1.Rows.Remove(row);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
private void Save_Click(object sender, EventArgs e)
|
69
|
+
{
|
70
|
+
using(var xw = XmlWriter.Create("todo.xml", new XmlWriterSettings { Indent = true, }))
|
71
|
+
{
|
72
|
+
var serializer = new DataContractSerializer(typeof(List<ToDoItem>));
|
73
|
+
serializer.WriteObject(xw, toDoItemBindingSource.List);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
```
|
79
|
+
|
80
|
+
```cs:Form1.Designer.cs
|
81
|
+
namespace Questions245208
|
82
|
+
{
|
83
|
+
partial class Form1
|
84
|
+
{
|
85
|
+
/// <summary>
|
86
|
+
/// 必要なデザイナー変数です。
|
87
|
+
/// </summary>
|
88
|
+
private System.ComponentModel.IContainer components = null;
|
89
|
+
|
90
|
+
/// <summary>
|
91
|
+
/// 使用中のリソースをすべてクリーンアップします。
|
92
|
+
/// </summary>
|
93
|
+
/// <param name="disposing">マネージド リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
|
94
|
+
protected override void Dispose(bool disposing)
|
95
|
+
{
|
96
|
+
if(disposing && (components != null))
|
97
|
+
{
|
98
|
+
components.Dispose();
|
99
|
+
}
|
100
|
+
base.Dispose(disposing);
|
101
|
+
}
|
102
|
+
|
103
|
+
#region Windows フォーム デザイナーで生成されたコード
|
104
|
+
|
105
|
+
/// <summary>
|
106
|
+
/// デザイナー サポートに必要なメソッドです。このメソッドの内容を
|
107
|
+
/// コード エディターで変更しないでください。
|
108
|
+
/// </summary>
|
109
|
+
private void InitializeComponent()
|
110
|
+
{
|
111
|
+
this.components = new System.ComponentModel.Container();
|
112
|
+
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
113
|
+
this.Add = new System.Windows.Forms.Button();
|
114
|
+
this.Delete = new System.Windows.Forms.Button();
|
115
|
+
this.Save = new System.Windows.Forms.Button();
|
116
|
+
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
|
117
|
+
this.textBox1 = new System.Windows.Forms.TextBox();
|
118
|
+
this.completedColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
|
119
|
+
this.deadlineColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
120
|
+
this.taskColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
121
|
+
this.toDoItemBindingSource = new System.Windows.Forms.BindingSource(this.components);
|
122
|
+
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
|
123
|
+
((System.ComponentModel.ISupportInitialize)(this.toDoItemBindingSource)).BeginInit();
|
124
|
+
this.SuspendLayout();
|
125
|
+
//
|
126
|
+
// dataGridView1
|
127
|
+
//
|
128
|
+
this.dataGridView1.AutoGenerateColumns = false;
|
129
|
+
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
130
|
+
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
131
|
+
this.completedColumn,
|
132
|
+
this.deadlineColumn,
|
133
|
+
this.taskColumn});
|
134
|
+
this.dataGridView1.DataSource = this.toDoItemBindingSource;
|
135
|
+
this.dataGridView1.Location = new System.Drawing.Point(12, 34);
|
136
|
+
this.dataGridView1.Name = "dataGridView1";
|
137
|
+
this.dataGridView1.RowTemplate.Height = 21;
|
138
|
+
this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
139
|
+
this.dataGridView1.Size = new System.Drawing.Size(604, 404);
|
140
|
+
this.dataGridView1.TabIndex = 0;
|
141
|
+
//
|
142
|
+
// Add
|
143
|
+
//
|
144
|
+
this.Add.Location = new System.Drawing.Point(622, 352);
|
145
|
+
this.Add.Name = "Add";
|
146
|
+
this.Add.Size = new System.Drawing.Size(80, 40);
|
147
|
+
this.Add.TabIndex = 1;
|
148
|
+
this.Add.Text = "登録";
|
149
|
+
this.Add.UseVisualStyleBackColor = true;
|
150
|
+
this.Add.Click += new System.EventHandler(this.Add_Click);
|
151
|
+
//
|
152
|
+
// Delete
|
153
|
+
//
|
154
|
+
this.Delete.Location = new System.Drawing.Point(708, 352);
|
155
|
+
this.Delete.Name = "Delete";
|
156
|
+
this.Delete.Size = new System.Drawing.Size(80, 40);
|
157
|
+
this.Delete.TabIndex = 2;
|
158
|
+
this.Delete.Text = "削除";
|
159
|
+
this.Delete.UseVisualStyleBackColor = true;
|
160
|
+
this.Delete.Click += new System.EventHandler(this.Delete_Click);
|
161
|
+
//
|
162
|
+
// Save
|
163
|
+
//
|
164
|
+
this.Save.Location = new System.Drawing.Point(622, 398);
|
165
|
+
this.Save.Name = "Save";
|
166
|
+
this.Save.Size = new System.Drawing.Size(166, 40);
|
167
|
+
this.Save.TabIndex = 3;
|
168
|
+
this.Save.Text = "保存";
|
169
|
+
this.Save.UseVisualStyleBackColor = true;
|
170
|
+
this.Save.Click += new System.EventHandler(this.Save_Click);
|
171
|
+
//
|
172
|
+
// dateTimePicker1
|
173
|
+
//
|
174
|
+
this.dateTimePicker1.Location = new System.Drawing.Point(623, 62);
|
175
|
+
this.dateTimePicker1.Name = "dateTimePicker1";
|
176
|
+
this.dateTimePicker1.Size = new System.Drawing.Size(166, 19);
|
177
|
+
this.dateTimePicker1.TabIndex = 4;
|
178
|
+
//
|
179
|
+
// textBox1
|
180
|
+
//
|
181
|
+
this.textBox1.Location = new System.Drawing.Point(624, 105);
|
182
|
+
this.textBox1.Name = "textBox1";
|
183
|
+
this.textBox1.Size = new System.Drawing.Size(165, 19);
|
184
|
+
this.textBox1.TabIndex = 5;
|
185
|
+
//
|
186
|
+
// completedColumn
|
187
|
+
//
|
188
|
+
this.completedColumn.DataPropertyName = "Completed";
|
189
|
+
this.completedColumn.HeaderText = "完了";
|
190
|
+
this.completedColumn.Name = "completedColumn";
|
191
|
+
this.completedColumn.Width = 50;
|
192
|
+
//
|
193
|
+
// deadlineColumn
|
194
|
+
//
|
195
|
+
this.deadlineColumn.DataPropertyName = "Deadline";
|
196
|
+
this.deadlineColumn.HeaderText = "期限";
|
197
|
+
this.deadlineColumn.Name = "deadlineColumn";
|
198
|
+
//
|
199
|
+
// taskColumn
|
200
|
+
//
|
201
|
+
this.taskColumn.DataPropertyName = "Task";
|
202
|
+
this.taskColumn.HeaderText = "やること";
|
203
|
+
this.taskColumn.Name = "taskColumn";
|
204
|
+
this.taskColumn.Width = 300;
|
205
|
+
//
|
206
|
+
// toDoItemBindingSource
|
207
|
+
//
|
208
|
+
this.toDoItemBindingSource.DataSource = typeof(Questions245208.ToDoItem);
|
209
|
+
//
|
210
|
+
// Form1
|
211
|
+
//
|
212
|
+
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
213
|
+
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
214
|
+
this.ClientSize = new System.Drawing.Size(800, 450);
|
215
|
+
this.Controls.Add(this.textBox1);
|
216
|
+
this.Controls.Add(this.dateTimePicker1);
|
217
|
+
this.Controls.Add(this.Save);
|
218
|
+
this.Controls.Add(this.Delete);
|
219
|
+
this.Controls.Add(this.Add);
|
220
|
+
this.Controls.Add(this.dataGridView1);
|
221
|
+
this.Name = "Form1";
|
222
|
+
this.Text = "Form1";
|
223
|
+
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
|
224
|
+
((System.ComponentModel.ISupportInitialize)(this.toDoItemBindingSource)).EndInit();
|
225
|
+
this.ResumeLayout(false);
|
226
|
+
this.PerformLayout();
|
227
|
+
|
228
|
+
}
|
229
|
+
|
230
|
+
#endregion
|
231
|
+
|
232
|
+
private System.Windows.Forms.DataGridView dataGridView1;
|
233
|
+
private System.Windows.Forms.Button Add;
|
234
|
+
private System.Windows.Forms.Button Delete;
|
235
|
+
private System.Windows.Forms.Button Save;
|
236
|
+
private System.Windows.Forms.DateTimePicker dateTimePicker1;
|
237
|
+
private System.Windows.Forms.TextBox textBox1;
|
238
|
+
private System.Windows.Forms.BindingSource toDoItemBindingSource;
|
239
|
+
private System.Windows.Forms.DataGridViewCheckBoxColumn completedColumn;
|
240
|
+
private System.Windows.Forms.DataGridViewTextBoxColumn deadlineColumn;
|
241
|
+
private System.Windows.Forms.DataGridViewTextBoxColumn taskColumn;
|
242
|
+
}
|
243
|
+
}
|
250
244
|
```
|