private void AddNewAddonButtonClick(object sender, EventArgs e) { // create empty instance of specified type if (SelectNewAddonTypeComboBox.SelectedIndex == -1) { return; } try { D3dVisibleAddon newAddon = null; Control controlToAdd = null; AddonType addonType = (AddonType)Enum.Parse(typeof(AddonType), SelectNewAddonTypeComboBox.SelectedItem.ToString()); switch (addonType) { case AddonType.D3dImage: newAddon = new ImageD3dVisibleAddon(GetNextAvailableAddonId(), AddonType.D3dImage, new VisibleLayout()); controlToAdd = _imageAddonPropertiesControl; break; case AddonType.D3dText: //check if already a text exists. only 1 allowed foreach (object item in AddonsListBox.Items) { if (item.ToString().Contains(AddonType.D3dText.ToString())) { throw new GeneralException("Cannot add more than one text addond"); } } newAddon = new TextD3dVisibleAddon(GetNextAvailableAddonId(), AddonType.D3dText, new VisibleLayout()); controlToAdd = _textAddonPropertiesControl; break; default: break; } // set correct properties panel SetAddonPropertiesControl(newAddon); // add control to lists _addons.Add(newAddon); AddonsListBox.Items.Add(newAddon.Id.ToString() + ". " + addonType.ToString()); // throw event for new addon created if (AddonSetEvent != null) { AddonSetEvent(newAddon); } } catch (System.Exception) { } }
private void OnTextChangedEvent(string text) { try { D3dVisibleAddon addon = GetCurrentAddon(); ((TextD3dVisibleAddon)addon).Text = text; // forward event if (AddonSetEvent != null) { AddonSetEvent(addon); } } catch (System.Exception) { } }
private void OnLayoutChangedEvent(VisibleLayout layout) { try { D3dVisibleAddon addon = GetCurrentAddon(); addon.Layout = layout; // forward event if (AddonSetEvent != null) { AddonSetEvent(addon); } } catch (System.Exception) { } }
private void SetAddonPropertiesControl(D3dVisibleAddon addon) { AddonPropertiesPanel.Controls.Clear(); switch (addon.Type) { case AddonType.D3dImage: _imageAddonPropertiesControl.Layout = addon.Layout; _imageAddonPropertiesControl.ImageFilename = ((ImageD3dVisibleAddon)addon).ImageFilename; AddonPropertiesPanel.Controls.Add(_imageAddonPropertiesControl); break; case AddonType.D3dText: AddonPropertiesPanel.Controls.Add(_textAddonPropertiesControl); break; default: break; } }
private void removeToolStripMenuItemClick(object sender, EventArgs e) { try { uint currentAddonId = GetSelectedAddonId(); // find appropriate addon D3dVisibleAddon foundAddon = null; foreach (D3dVisibleAddon addon in _addons) { if (addon.Id == currentAddonId) { foundAddon = addon; break; } } // remove both if (foundAddon != null) { _addons.Remove(foundAddon); AddonsListBox.Items.Remove(AddonsListBox.SelectedItem); if (AddonRemovedEvent != null) { AddonRemovedEvent((int)foundAddon.Id); } } //if it was the last one, empty properties control if (_addons.Count == 0) { AddonPropertiesPanel.Controls.Clear(); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
private D3dVisibleAddon GetCurrentAddon() { // get selected addon D3dVisibleAddon currentAddon = null; try { uint currentAddonId = GetSelectedAddonId(); foreach (D3dVisibleAddon addon in _addons) { if (addon.Id == currentAddonId) { currentAddon = addon; break; } } } catch (System.Exception) { } return(currentAddon); }
void OnImageFileChangedEvent(FileInfo imageFile) { try { D3dVisibleAddon addon = GetCurrentAddon(); if (addon.Type != AddonType.D3dImage) { // Problem! } ((ImageD3dVisibleAddon)addon).ImageFilename = imageFile.FullName; // forward event if (AddonSetEvent != null) { AddonSetEvent(addon); } } catch (System.Exception) { } }
private void AddonsListBoxSelectedIndexChanged(object sender, EventArgs e) { try { // find addon Id uint currentAddonId = GetSelectedAddonId(); D3dVisibleAddon currentAddon = null; foreach (D3dVisibleAddon addon in _addons) { if (addon.Id == currentAddonId) { currentAddon = addon; break; } } // set appropriate addon properties control SetAddonPropertiesControl(currentAddon); } catch (System.Exception) { } }