123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using System;
- using System.Windows.Forms;
- using 名单编辑器.Properties;
- namespace 名单编辑器
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- Settings.Default.isediting = false;
- Settings.Default.Save();
- }
- private static int num = 0;
- private void button1_Click(object sender, EventArgs e)
- {
- Settings.Default.isediting = true;
- Settings.Default.Save();
- listView1.BeginUpdate();
- for (int i = 0; i < textBox1.Lines.Length; i++)
- {
- ListViewItem listViewItem = new ListViewItem
- {
- Text = textBox1.Lines[i]
- };
- if (listViewItem.Text != "" | listViewItem.Text != string.Empty)
- {
- listView1.Items.Add(listViewItem);
- num++;
- 保存SToolStripButton.Enabled = true;
- }
- }
- listView1.EndUpdate();
- toolStripStatusLabel2.Text = num.ToString();
- }
- private void listView1_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyValue == 46)
- {
- for (int i = listView1.SelectedItems.Count - 1; i >= 0; i--)
- {
- ListViewItem item = listView1.SelectedItems[i];
- listView1.Items.Remove(item);
- num--;
- toolStripStatusLabel2.Text = num.ToString();
- }
- }
- }
- private void 保存SToolStripButton_Click(object sender, EventArgs e)
- {
- if (Settings.Default.isediting == true)
- {
- if (num == 0)
- MessageBox.Show(Resources.NullNumSaveErr, Resources.NullNumSaveErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
- else
- {
- Program.Save();
- Settings.Default.isediting = false;
- Settings.Default.Save();
- }
- }
- else
- MessageBox.Show(Resources.NullSaveErr, Resources.NullSaveErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- private void 新建NToolStripButton_Click(object sender, EventArgs e)
- {
- if (Settings.Default.isediting)
- {
- DialogResult = MessageBox.Show(Resources.NewButEdited, Resources.NewButEditedTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
- if (DialogResult == DialogResult.Yes)
- {
- MessageBox.Show("Y");
- Program.Save();
- Program.New();
- }
- if (DialogResult == DialogResult.No)
- {
- MessageBox.Show("N");
- }
- }
- else
- Program.New();
- }
- private void toolStripButton1_Click(object sender, EventArgs e)
- {
- for (int i = listView1.SelectedItems.Count - 1; i >= 0; i--)
- {
- ListViewItem item = listView1.SelectedItems[i];
- listView1.Items.Remove(item);
- num--;
- toolStripStatusLabel2.Text = num.ToString();
- if (num == 0)
- toolStripButton1.Enabled = false;
- }
- }
- private void textBox1_Enter(object sender, EventArgs e)
- {
- 剪切UToolStripButton.Enabled = true;
- 复制CToolStripButton.Enabled = true;
- 粘贴PToolStripButton.Enabled = true;
- }
- private void textBox1_Leave(object sender, EventArgs e)
- {
- 剪切UToolStripButton.Enabled = false;
- 复制CToolStripButton.Enabled = false;
- 粘贴PToolStripButton.Enabled = false;
- }
- private void listView1_Enter(object sender, EventArgs e)
- {
- if (num != 0)
- toolStripButton1.Enabled = true;
- }
- private void listView1_Leave(object sender, EventArgs e)
- {
- toolStripButton1.Enabled = false;
- }
- private void 复制CToolStripButton_Click(object sender, EventArgs e)
- {
- if(textBox1.SelectionLength == 0)
- {
- textBox1.SelectAll();
- }
- else
- {
- textBox1.Copy();
- }
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (Settings.Default.isediting)
- {
- if (MessageBox.Show(Resources.ExitContent, Resources.ExitCTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
- {
- Environment.Exit(0);
- }
- else
- {
- e.Cancel = true;
- }
- }
- else
- {
- Environment.Exit(0);
- }
- }
- }
- }
|