Form1.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using System;
  2. using System.Windows.Forms;
  3. using 名单编辑器.Properties;
  4. namespace 名单编辑器
  5. {
  6. public partial class Form1 : Form
  7. {
  8. public Form1()
  9. {
  10. InitializeComponent();
  11. Settings.Default.isediting = false;
  12. Settings.Default.Save();
  13. }
  14. private static int num = 0;
  15. private void button1_Click(object sender, EventArgs e)
  16. {
  17. Settings.Default.isediting = true;
  18. Settings.Default.Save();
  19. listView1.BeginUpdate();
  20. for (int i = 0; i < textBox1.Lines.Length; i++)
  21. {
  22. ListViewItem listViewItem = new ListViewItem
  23. {
  24. Text = textBox1.Lines[i]
  25. };
  26. if (listViewItem.Text != "" | listViewItem.Text != string.Empty)
  27. {
  28. listView1.Items.Add(listViewItem);
  29. num++;
  30. 保存SToolStripButton.Enabled = true;
  31. }
  32. }
  33. listView1.EndUpdate();
  34. toolStripStatusLabel2.Text = num.ToString();
  35. }
  36. private void listView1_KeyUp(object sender, KeyEventArgs e)
  37. {
  38. if (e.KeyValue == 46)
  39. {
  40. for (int i = listView1.SelectedItems.Count - 1; i >= 0; i--)
  41. {
  42. ListViewItem item = listView1.SelectedItems[i];
  43. listView1.Items.Remove(item);
  44. num--;
  45. toolStripStatusLabel2.Text = num.ToString();
  46. }
  47. }
  48. }
  49. private void 保存SToolStripButton_Click(object sender, EventArgs e)
  50. {
  51. if (Settings.Default.isediting == true)
  52. {
  53. if (num == 0)
  54. MessageBox.Show(Resources.NullNumSaveErr, Resources.NullNumSaveErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
  55. else
  56. {
  57. Program.Save();
  58. Settings.Default.isediting = false;
  59. Settings.Default.Save();
  60. }
  61. }
  62. else
  63. MessageBox.Show(Resources.NullSaveErr, Resources.NullSaveErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
  64. }
  65. private void 新建NToolStripButton_Click(object sender, EventArgs e)
  66. {
  67. if (Settings.Default.isediting)
  68. {
  69. DialogResult = MessageBox.Show(Resources.NewButEdited, Resources.NewButEditedTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  70. if (DialogResult == DialogResult.Yes)
  71. {
  72. MessageBox.Show("Y");
  73. Program.Save();
  74. Program.New();
  75. }
  76. if (DialogResult == DialogResult.No)
  77. {
  78. MessageBox.Show("N");
  79. }
  80. }
  81. else
  82. Program.New();
  83. }
  84. private void toolStripButton1_Click(object sender, EventArgs e)
  85. {
  86. for (int i = listView1.SelectedItems.Count - 1; i >= 0; i--)
  87. {
  88. ListViewItem item = listView1.SelectedItems[i];
  89. listView1.Items.Remove(item);
  90. num--;
  91. toolStripStatusLabel2.Text = num.ToString();
  92. if (num == 0)
  93. toolStripButton1.Enabled = false;
  94. }
  95. }
  96. private void textBox1_Enter(object sender, EventArgs e)
  97. {
  98. 剪切UToolStripButton.Enabled = true;
  99. 复制CToolStripButton.Enabled = true;
  100. 粘贴PToolStripButton.Enabled = true;
  101. }
  102. private void textBox1_Leave(object sender, EventArgs e)
  103. {
  104. 剪切UToolStripButton.Enabled = false;
  105. 复制CToolStripButton.Enabled = false;
  106. 粘贴PToolStripButton.Enabled = false;
  107. }
  108. private void listView1_Enter(object sender, EventArgs e)
  109. {
  110. if (num != 0)
  111. toolStripButton1.Enabled = true;
  112. }
  113. private void listView1_Leave(object sender, EventArgs e)
  114. {
  115. toolStripButton1.Enabled = false;
  116. }
  117. private void 复制CToolStripButton_Click(object sender, EventArgs e)
  118. {
  119. if(textBox1.SelectionLength == 0)
  120. {
  121. textBox1.SelectAll();
  122. }
  123. else
  124. {
  125. textBox1.Copy();
  126. }
  127. }
  128. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  129. {
  130. if (Settings.Default.isediting)
  131. {
  132. if (MessageBox.Show(Resources.ExitContent, Resources.ExitCTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
  133. {
  134. Environment.Exit(0);
  135. }
  136. else
  137. {
  138. e.Cancel = true;
  139. }
  140. }
  141. else
  142. {
  143. Environment.Exit(0);
  144. }
  145. }
  146. }
  147. }