public static FlowMap Open(Form mdiparent) { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == DialogResult.OK) { String loc = dlg.FileName; FlowDocument olddoc = FlowDocument.FindDocument(loc); if (olddoc != null) { IList windows = FlowMap.FindWindows(mdiparent, olddoc); if (windows.Count > 0) { FlowMap w = windows[0] as FlowMap; if (w.Reload()) { w.Show(); w.Activate(); } return(w); } } else { Stream file = dlg.OpenFile(); if (file != null) { FlowDocument doc = null; try { doc = FlowDocument.Load(file, loc); } catch (Exception ex) { MessageBox.Show(mdiparent, ex.Message, "Error reading design from a file"); } finally { file.Close(); } if (doc != null) { FlowMap w = new FlowMap(); w.View.Document = doc; w.MdiParent = mdiparent; w.Show(); w.Activate(); return(w); } } } } return(null); }
public virtual bool Reload() { String loc = this.Doc.Location; if (loc != "") { FileStream file = File.Open(loc, FileMode.Open); FlowDocument olddoc = this.View.Doc; FlowDocument newdoc = null; try { newdoc = FlowDocument.Load(file, loc); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error reading design from a file"); return(false); } finally { file.Close(); } if (newdoc != null) { IList windows = FlowMap.FindWindows(this.MdiParent, olddoc); foreach (Object obj in windows) { FlowMap w = obj as FlowMap; if (w != null) { w.View.Document = newdoc; } } } } return(true); }