質問編集履歴
1
画像の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,4 +6,49 @@
|
|
6
6
|
しかしこれだと、固定数値や文字列を編集したいときに手動で編集する必要があります。
|
7
7
|
本来こういった固定数値や文字列をプログラム側から編集はしないのが一般的ですが、ユーザがある程度設定を変更できるインターフェースを作りたいときに不便です。
|
8
8
|
|
9
|
-
app.configに保存するのではなく、別の場所(例えばテキストファイルとか)に保存・取得・編集ができる方法はありませんでしょうか?
|
9
|
+
app.configに保存するのではなく、別の場所(例えばテキストファイルとか)に保存・取得・編集ができる方法はありませんでしょうか?
|
10
|
+
|
11
|
+
追記:app.configを利用して同じものができました。
|
12
|
+
こんな感じのものをapp.configを使わずに作りたいと思っています。
|
13
|
+
|
14
|
+

|
15
|
+
|
16
|
+
プログラムは以下の通りです。
|
17
|
+
public partial class frmEditConfig : Form
|
18
|
+
{
|
19
|
+
public frmEditConfig()
|
20
|
+
{
|
21
|
+
InitializeComponent();
|
22
|
+
}
|
23
|
+
|
24
|
+
private void frmEditConfig_Load(object sender, EventArgs e)
|
25
|
+
{
|
26
|
+
loadDGV();
|
27
|
+
}
|
28
|
+
|
29
|
+
private void loadDGV()
|
30
|
+
{
|
31
|
+
dataGridView1.Rows.Clear();
|
32
|
+
for (int i = 0; i < ConfigurationManager.AppSettings.Count; i++)
|
33
|
+
{
|
34
|
+
dataGridView1.Rows.Add();
|
35
|
+
dataGridView1[0, i].Value = ConfigurationManager.AppSettings.Keys[i];
|
36
|
+
dataGridView1[1, i].Value = ConfigurationManager.AppSettings[i];
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
41
|
+
{
|
42
|
+
textBox1.Text = dataGridView1[0, e.RowIndex].Value.ToString();
|
43
|
+
textBox2.Text = dataGridView1[1, e.RowIndex].Value.ToString();
|
44
|
+
}
|
45
|
+
|
46
|
+
private void button1_Click(object sender, EventArgs e)
|
47
|
+
{
|
48
|
+
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
49
|
+
|
50
|
+
config.AppSettings.Settings[textBox1.Text].Value = textBox2.Text;
|
51
|
+
config.Save(ConfigurationSaveMode.Full);
|
52
|
+
loadDGV();
|
53
|
+
}
|
54
|
+
}
|