public override void OnLoadedFromXmlFile(DrawingItem obj, IDesignPane designPane, IDrawDesignControl designControl) { Point p0 = this.Location; this.Copy(obj); //contained objects are cloned in _items if (this.Page != null && this.Page.InDesignMode) { DrawGroupBox dgb = obj as DrawGroupBox; if (dgb != null) { IList <DrawingItem> lst = dgb.Items; //cloned in _items if (lst != null && designPane != null && designControl != null) { //for each object, create a designer control and assign it to the control Control ctrl = designControl as Control; //control corresponding to this object foreach (DrawingItem di in lst) { Type t = di.GetType(); object[] vs = t.GetCustomAttributes(typeof(TypeMappingAttribute), true); if (vs != null && vs.Length > 0) { TypeMappingAttribute tm = vs[0] as TypeMappingAttribute; if (tm != null) { //create designer control IComponent ic = designPane.CreateComponent(tm.MappedType, di.Name); IDrawDesignControl idc = ic as IDrawDesignControl; Control c = ic as Control; DrawingItem d0 = idc.Item; //auto-created object, should be deleted ctrl.Controls.Add(c); idc.Item = GetItemByID(di.DrawingId); //use cloned object for the new control c.Location = di.Location; if (_items != null) { //remove auto-created object d0 for (int i = 0; i < _items.Count; i++) { if (d0 == _items[i] || d0.DrawingId == _items[i].DrawingId) { _items.RemoveAt(i); break; } } } } } } } } } this.Location = p0; }
private void mi_loadDrawing(object sender, EventArgs e) { MenuItem mi = sender as MenuItem; if (mi != null) { IDrawDesignControl drc = mi.Tag as IDrawDesignControl; if (drc != null && drc.Item != null) { IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host != null) { HostSurface surface = host.GetService(typeof(DesignSurface)) as HostSurface; if (surface != null) { ClassPointer root = surface.Loader.GetRootId(); if (root != null) { ILimnorDesignerLoader ldp = root.GetDesignerLoader(); if (ldp != null) { IDesignPane idp = ldp.DesignPane as IDesignPane; OpenFileDialog dlg = new OpenFileDialog(); dlg.CheckFileExists = true; dlg.DefaultExt = ".xml"; dlg.Filter = "XML files|*.xml"; dlg.Title = "Select XML file for loading drawing"; if (dlg.ShowDialog(drc.Item.Page) == DialogResult.OK) { drc.Item.LoadDrawingsFromFile(dlg.FileName, idp, drc); } } } } } } } }