private void miEditPaste_Click(object sender, EventArgs e) { var ed = CurrentEditor; if (Clipboard.ContainsFileDropList()) { var files = Clipboard.GetFileDropList(); if (files.Count < 1) { return; } else if (files.Count == 1) { string filename = files[0]; if (ed == null) { LoadImage(filename); } else { ed.LoadImage(filename); } } else { TabPage tab = null; foreach (string filename in files) { tab = LoadImage(filename) ?? tab; } if (tab != null) { tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(tab); } } } else if (Clipboard.ContainsImage()) { var img = Clipboard.GetImage(); if (ed == null) { string key = string.Format("CB-{0:X}", DateTime.Now.ToBinary()); tabControl1.TabPages.Add(key, "[Clipboard]"); var tab = tabControl1.TabPages[key]; ed = new ImageEditor(); tab.Controls.Add(ed); ed.Dock = DockStyle.Fill; ed.Close += Editor_Close; } ed.SetImage(img); } }
/// <summary>Create new ImageEditor for specified filename, or select existing tab if image already loaded</summary> /// <param name="filename">Image file to load</param> /// <returns>Newly create or selected tab</returns> private TabPage LoadImage(string filename) { // try loading image try { Image.FromFile(filename); } catch { MessageBox.Show(string.Format("Failed to open image file:\n\n{0}", filename), "Load Failed"); return null; } if (tabControl1.TabPages.ContainsKey(filename)) return tabControl1.TabPages[filename] ; tabControl1.TabPages.Add(filename, Path.GetFileNameWithoutExtension(filename)); var tab = tabControl1.TabPages[filename]; var editor = new ImageEditor(); tab.Controls.Add(editor); editor.Dock = DockStyle.Fill; editor.Close += Editor_Close; editor.LoadImage(filename); return tab; }
private void miEditPaste_Click(object sender, EventArgs e) { var ed = CurrentEditor; if (Clipboard.ContainsFileDropList()) { var files = Clipboard.GetFileDropList(); if (files.Count < 1) return; else if (files.Count == 1) { string filename = files[0]; if (ed == null) LoadImage(filename); else ed.LoadImage(filename); } else { TabPage tab = null; foreach (string filename in files) tab = LoadImage(filename) ?? tab; if (tab != null) tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(tab); } } else if (Clipboard.ContainsImage()) { var img = Clipboard.GetImage(); if (ed == null) { string key = string.Format("CB-{0:X}", DateTime.Now.ToBinary()); tabControl1.TabPages.Add(key, "[Clipboard]"); var tab = tabControl1.TabPages[key]; ed = new ImageEditor(); tab.Controls.Add(ed); ed.Dock = DockStyle.Fill; ed.Close += Editor_Close; } ed.SetImage(img); } }