// ------------------------------------------------------------------- // button_Click // ------------------------------------------------------------------- private void button_Click(object sender, EventArgs e) { DialogEnterNumber dialog = new DialogEnterNumber(listBox.Items.Count, Min, Max, ModelList); if (dialog.ShowDialog() == DialogResult.OK) { // Suppress if (listBox.Items.Count > dialog.Value) { int nb = listBox.Items.Count - dialog.Value; for (int i = 0; i < nb; i++) { listBox.Items.RemoveAt(dialog.Value); } } // Add else if (listBox.Items.Count < dialog.Value) { int nb = dialog.Value - listBox.Items.Count; for (int i = 0; i < nb; i++) { SuperListItem defaultValue = (SuperListItem)Activator.CreateInstance(TypeItem, listBox.Items.Count + 1); listBox.Items.Add(defaultValue); } } } }
// ------------------------------------------------------------------- // PasteItem // ------------------------------------------------------------------- public void PasteItem() { if (CopiedItem != null) { CopiedItem.Id = ((SuperListItem)listBox.Items[listBox.SelectedIndex]).Id; listBox.Items[listBox.SelectedIndex] = CopiedItem; CopiedItem = CopiedItem.CreateCopy(); } }
// ------------------------------------------------------------------- // textBoxName_TextChanged // ------------------------------------------------------------------- private void textBoxName_TextChanged(object sender, EventArgs e) { listBoxComplete.SetName(textBoxName.Text); SuperListItem item = (SuperListItem)listBoxComplete.GetListBox().SelectedItem; for (int i = 0; i < listBoxTileset.GetListBox().Items.Count; i++) { if (item.Id == ((SuperListItem)listBoxTileset.GetListBox().Items[i]).Id) { listBoxTileset.GetListBox().Items[i] = item; } } }
// ------------------------------------------------------------------- // AddItem // ------------------------------------------------------------------- public void AddItem() { SuperListItem item = (SuperListItem)listBoxComplete.GetListBox().SelectedItem; bool test = true; for (int i = 0; i < listBoxTileset.GetListBox().Items.Count; i++) { if (item.Id == ((SuperListItem)listBoxTileset.GetListBox().Items[i]).Id) { test = false; break; } } if (test) { listBoxTileset.GetListBox().Items.Add(item); if (listBoxTileset.GetListBox().Items.Count == 1) { listBoxTileset.GetListBox().SelectedIndex = 0; } } }
// ------------------------------------------------------------------- // DeleteItem // ------------------------------------------------------------------- public void DeleteItem() { SuperListItem defaultValue = (SuperListItem)Activator.CreateInstance(TypeItem, ((SuperListItem)listBox.Items[listBox.SelectedIndex]).Id); listBox.Items[listBox.SelectedIndex] = defaultValue; }
// ------------------------------------------------------------------- // CopyItem // ------------------------------------------------------------------- public void CopyItem() { CopiedItem = ((SuperListItem)listBox.Items[listBox.SelectedIndex]).CreateCopy(); }