This repository was archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEditSetting.cs
More file actions
123 lines (102 loc) · 3.28 KB
/
Copy pathEditSetting.cs
File metadata and controls
123 lines (102 loc) · 3.28 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Hearts_of_Oak_Packager
{
public partial class EditSetting : Form
{
public EditSetting()
{
InitializeComponent();
}
private string _setting;
private string _FileName;
//private List<string> _items = new List<string>();
BindingList<string> _list = new BindingList<string>();
public string setting
{
get
{
return _setting;
}
set
{
_setting = value;
_FileName = _setting + ".txt";
}
}
void _list_ListChanged(object sender, ListChangedEventArgs e)
{
btnSave.Enabled = true;
}
private void EditSetting_Load(object sender, EventArgs e)
{
this.Text = "Edit " + _setting + " File";
//load the file
if (File.Exists(_FileName)) {
AddRange(File.ReadAllLines(_FileName));
}
_list.ListChanged += _list_ListChanged;
//parse into the listbox
lbxSettings.DataSource = _list;
lbxSettings.Refresh();
}
public void AddRange(IEnumerable<string> collection)
{
foreach (var i in collection) _list.Add(i);
}
private void btnAdd_Click(object sender, EventArgs e)
{
_list.Add(txbAdd.Text);
}
private void btnSave_Click(object sender, EventArgs e)
{
File.WriteAllLines(_FileName, _list);
btnSave.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (lbxSettings.SelectedItems.Count > 0)
{
btnRemove.Enabled = true;
}
else
{
btnRemove.Enabled = false;
}
}
private void btnRemove_Click(object sender, EventArgs e)
{
_list.Remove(lbxSettings.SelectedItem.ToString());
}
private void EditSetting_FormClosing(object sender, FormClosingEventArgs e)
{
if (btnSave.Enabled)
{
string mbxText = "Do you want to save changes to settings file?";
string mbxTitle = "Save " + _FileName + " settings";
MessageBoxButtons mbxButton = MessageBoxButtons.YesNoCancel;
MessageBoxIcon mbxIcon = MessageBoxIcon.Warning;
DialogResult result = MessageBox.Show(mbxText, mbxTitle, mbxButton, mbxIcon);
switch (result)
{
case System.Windows.Forms.DialogResult.Yes:
btnSave.PerformClick();
this.Close();
break;
case System.Windows.Forms.DialogResult.No:
break;
case System.Windows.Forms.DialogResult.Cancel:
e.Cancel = true;
break;
}
}
}
}
}