/// <summary> /// 复制 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void Copy(object sender, EventArgs args) { //序列化服务 IDesignerSerializationService serialService = this.GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService; //设计宿主 IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost; //选择服务 ISelectionService selection = GetService(typeof(ISelectionService)) as ISelectionService; ICollection selectedComponents = selection.GetSelectedComponents(); ArrayList toCopy = new ArrayList(); //获取当前选中的组件序列化 foreach (object component in selectedComponents) { if (component == host.RootComponent) { continue; } toCopy.Add(component); ComponentDesigner designer = host.GetDesigner((IComponent)component) as ComponentDesigner; if (designer != null && designer.AssociatedComponents != null) { toCopy.AddRange(designer.AssociatedComponents); } } List <EntityCPNode> stateData = serialService.Serialize(toCopy) as List <EntityCPNode>; clipboardData = stateData; }
object IDesignerSerializationService.Serialize(ICollection objects) { IDesignerSerializationService service = LoaderHost.GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService; if (service != null) { return(service.Serialize(objects)); } return(null); }
ICollection IDesignerSerializationService.Deserialize(object serializationData) { IDesignerSerializationService service = LoaderHost.GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService; if (service != null) { return(service.Deserialize(serializationData)); } return(new object[0]); }
void ExecuteCopy(object sender, EventArgs e) { ISelectionService ss = (ISelectionService)this.GetService(typeof(ISelectionService)); if (ss != null) { if (ss.PrimarySelection != null) { IDesignerSerializationService dss = (IDesignerSerializationService)this.GetService(typeof(IDesignerSerializationService)); if (dss != null) { object v = dss.Serialize(ss.GetSelectedComponents()); System.Windows.Forms.Clipboard.SetDataObject(new DataObject("DesignObject", v), true); } } } }
public void PerformFlushWorker() { IDesignerHost idh = (IDesignerHost)this.LoaderHost.GetService(typeof(IDesignerHost)); IDesignerSerializationService serService = this.GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService; List <IComponent> comps = new List <IComponent>(); foreach (IComponent comp in idh.Container.Components) { if (comp != idh.RootComponent)// && !nametable.ContainsKey(comp)) { comps.Add(comp); } } this._data = serService.Serialize(comps) as List <EntityCPNode>; }
void ExecutePaste(object sender, EventArgs e) { IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host != null) { IDesignerSerializationService dss = (IDesignerSerializationService)this.GetService(typeof(IDesignerSerializationService)); if (dss != null) { object v = System.Windows.Forms.Clipboard.GetData("DesignObject"); if (v != null) { ICollection cc = dss.Deserialize(v); if (cc != null) { using (DesignerTransaction trans = host.CreateTransaction("Paste")) { foreach (object x in cc) { if (x is IComponent) { host.Container.Add((IComponent)x); if (x is Control) { if (host.RootComponent is Control) { ((Control)host.RootComponent).Controls.Add((Control)x); ((Control)x).Location = new Point(((Control)x).Left + 10, ((Control)x).Top + 10); } } //notify } } ISelectionService selSvc = (ISelectionService)GetService(typeof(ISelectionService)); if (selSvc != null) { selSvc.SetSelectedComponents(cc, SelectionTypes.Replace); } trans.Commit(); enableUndoMenu(); } } } } } }
private void Copy(object sender, EventArgs args) { IDesignerSerializationService stateSerializer = GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService; IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost; ISelectionService selection = GetService(typeof(ISelectionService)) as ISelectionService; if (host == null || stateSerializer == null || selection == null) { return; } // copy selected components and their associated components ICollection selectedComponents = selection.GetSelectedComponents(); ArrayList toCopy = new ArrayList(); foreach (object component in selectedComponents) { if (component == host.RootComponent) { continue; } toCopy.Add(component); ComponentDesigner designer = host.GetDesigner((IComponent)component) as ComponentDesigner; if (designer != null && designer.AssociatedComponents != null) { toCopy.AddRange(designer.AssociatedComponents); } } object stateData = stateSerializer.Serialize(toCopy); _clipboard = stateData; // Console.WriteLine ("Copied components: "); // foreach (object c in toCopy) // Console.WriteLine (((IComponent)c).Site.Name); // // TODO: MWF X11 doesn't seem to support custom clipboard formats - bug #357642 // // MemoryStream stream = new MemoryStream (); // new BinaryFormatter().Serialize (stream, stateData); // stream.Seek (0, SeekOrigin.Begin); // byte[] serializedData = stream.GetBuffer (); // Clipboard.SetDataObject (new DataObject (DT_DATA_FORMAT, serializedData)); }
private object OnCreateService(IServiceContainer container, System.Type serviceType) { if (serviceType == typeof(ISelectionService)) { if (this.selectionService == null) { this.selectionService = new SampleSelectionService(this); } return(this.selectionService); } if (serviceType == typeof(IDesignerSerializationService)) { if (this.designerSerialService == null) { this.designerSerialService = new DesignerSerializationService(this); } return(this.designerSerialService); } if (serviceType == typeof(ITypeDescriptorFilterService)) { return(new SampleTypeDescriptorFilterService(this)); } if (serviceType == typeof(IToolboxService)) { if (this.toolboxService == null) { this.toolboxService = new SampleToolboxService(this); } return(this.toolboxService); } if (serviceType == typeof(IMenuCommandService)) { if (this.menuCommandService == null) { this.menuCommandService = new SampleMenuCommandService(this); } return(this.menuCommandService); } Debug.Fail("Service type " + serviceType.FullName + " requested but we don't support it"); return(null); }
/// <summary> /// 反序列化 /// </summary> /// <param name="rootControl"></param> /// <param name="errors"></param> private void Deserialize(Control rootControl, ArrayList errors) { try { //获取序列化反序列化服务 IDesignerSerializationService serService = this.GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService; //生成控件 List <Component> comps = serService.Deserialize(this._data) as List <Component>; foreach (Component com in comps) { if (com is Control) { //加载到设计面板 rootControl.Controls.Add(com as Control); } } } catch (Exception ex) { errors.Add(ex); } }
public void DesignerSerializationServiceCreated() { IDesignerSerializationService designerSerializationServiceCreated = (IDesignerSerializationService)loaderHost.GetService(typeof(IDesignerSerializationService)); Assert.IsTrue(designerSerializationServiceCreated is DesignerSerializationService); }
internal void Initialize( ) { Control control = null; DesignerHost = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (DesignerHost == null) { return; } ((ABCControls.ABCView)DesignerHost.RootComponent).Surface = this; try { #region Set the backcolor Type hostType = DesignerHost.RootComponent.GetType(); if (hostType == typeof(DevExpress.XtraEditors.XtraForm)) { control = this.View as Control; control.BackColor = Color.White; } else if (hostType == typeof(UserControl)) { control = this.View as Control; control.BackColor = Color.White; } else if (hostType == typeof(Component)) { control = this.View as Control; control.BackColor = Color.FloralWhite; } else if (hostType == typeof(ABCControls.ABCView)) { control = this.View as Control; // control.BackColor=Color.FloralWhite; } else { throw new Exception("Undefined Host Type: " + hostType.ToString()); } #endregion #region Set Services ServiceSelection = (ISelectionService)(this.ServiceContainer.GetService(typeof(ISelectionService))); ServiceComponentChange = (IComponentChangeService)this.ServiceContainer.GetService(typeof(IComponentChangeService)); ServiceMenuCommand = (IMenuCommandService)this.ServiceContainer.GetService(typeof(IMenuCommandService)); ServiceSerializer = (IDesignerSerializationService)this.ServiceContainer.GetService(typeof(IDesignerSerializationService)); #region Undo UndoEngine = new UndoEngineImpl(this.ServiceContainer); UndoEngine.CanUndoChanged += new EventHandler(UndoEngine_CanUndoChanged); UndoEngine.CanRedoChanged += new EventHandler(UndoEngine_CanRedoChanged); //disable the UndoEngine UndoEngine.Enabled = false; if (UndoEngine != null) { //- the UndoEngine is ready to be replaced this.ServiceContainer.RemoveService(typeof(UndoEngine), false); this.ServiceContainer.AddService(typeof(UndoEngine), UndoEngine); } #endregion NameCreationService = (INameCreationService)(this.GetService(typeof(INameCreationService))); #endregion ((System.Windows.Forms.Control)(this.View)).PreviewKeyDown += new PreviewKeyDownEventHandler(HostSurface_PreviewKeyDown); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } }
public void Deserialize(IServiceProvider serviceProvider, bool removeCurrentComponents) { if (serviceProvider == null) { serviceProvider = this.serviceProvider; } IDesignerSerializationService ds = (IDesignerSerializationService)serviceProvider.GetService(typeof(IDesignerSerializationService)); IDesignerHost host = null; DesignerTransaction trans = null; try { if (serializationData == null) { BinaryFormatter formatter = new BinaryFormatter(); #pragma warning disable SYSLIB0011 // Type or member is obsolete serializationData = formatter.Deserialize(SerializationStream); #pragma warning restore SYSLIB0011 // Type or member is obsolete } if (removeCurrentComponents && components != null) { foreach (IComponent removeComp in components) { if (host == null && removeComp.Site != null) { host = (IDesignerHost)removeComp.Site.GetService(typeof(IDesignerHost)); if (host != null) { trans = host.CreateTransaction(string.Format(SR.DragDropMoveComponents, components.Length)); } } if (host != null) { host.DestroyComponent(removeComp); } } components = null; } ICollection objects = ds.Deserialize(serializationData); components = new IComponent[objects.Count]; IEnumerator e = objects.GetEnumerator(); int idx = 0; while (e.MoveNext()) { components[idx++] = (IComponent)e.Current; } // only do top-level components here, // because other are already parented. // otherwise, when we process these // components it's too hard to know what we // should be reparenting. ArrayList topComps = new ArrayList(); for (int i = 0; i < components.Length; i++) { if (components[i] is Control) { Control c = (Control)components[i]; if (c.Parent == null) { topComps.Add(components[i]); } } else { topComps.Add(components[i]); } } components = topComps.ToArray(); } finally { if (trans != null) { trans.Commit(); } } }
protected override IComponent[] CreateComponentsCore(IDesignerHost host, IDictionary defaultValues) { IDesignerSerializationService ds = (IDesignerSerializationService)host.GetService(typeof(IDesignerSerializationService)); if (ds == null) { return(null); } // Deserialize to components collection // ICollection objects = ds.Deserialize(_serializationData); ArrayList components = new ArrayList(); foreach (object obj in objects) { if (obj != null && obj is IComponent) { components.Add(obj); } } IComponent[] componentsArray = new IComponent[components.Count]; components.CopyTo(componentsArray, 0); ArrayList trayComponents = null; // Parent and locate each Control // if (defaultValues == null) { defaultValues = new Hashtable(); } Control parentControl = defaultValues["Parent"] as Control; if (parentControl != null) { ParentControlDesigner parentControlDesigner = host.GetDesigner(parentControl) as ParentControlDesigner; if (parentControlDesigner != null) { // Determine bounds of all controls // Rectangle bounds = Rectangle.Empty; foreach (IComponent component in componentsArray) { Control childControl = component as Control; if (childControl != null && childControl != parentControl && childControl.Parent == null) { if (bounds.IsEmpty) { bounds = childControl.Bounds; } else { bounds = Rectangle.Union(bounds, childControl.Bounds); } } } defaultValues.Remove("Size"); // don't care about the drag size foreach (IComponent component in componentsArray) { Control childControl = component as Control; Form form = childControl as Form; if (childControl != null && !(form != null && form.TopLevel) && // Don't add top-level forms childControl.Parent == null) { defaultValues["Offset"] = new Size(childControl.Bounds.X - bounds.X, childControl.Bounds.Y - bounds.Y); parentControlDesigner.AddControl(childControl, defaultValues); } } } } // VSWhidbey 516338 - When creating an item for the tray, template items will have // an old location stored in them, so they may show up on top of other items. // So we need to call UpdatePastePositions for each one to get the tray to // arrange them properly. // ComponentTray tray = (ComponentTray)host.GetService(typeof(ComponentTray)); if (tray != null) { foreach (IComponent component in componentsArray) { ComponentTray.TrayControl c = tray.GetTrayControlFromComponent(component); if (c != null) { if (trayComponents == null) { trayComponents = new ArrayList(); } trayComponents.Add(c); } } if (trayComponents != null) { tray.UpdatePastePositions(trayComponents); } } return(componentsArray); }
// Reminder: We set control.Parent so that it gets serialized for Undo/Redo // private void Paste(object sender, EventArgs args) { IDesignerSerializationService stateSerializer = GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService; ISelectionService selection = GetService(typeof(ISelectionService)) as ISelectionService; IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost; IComponentChangeService changeService = GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (host == null || stateSerializer == null) { return; } // // TODO: MWF X11 doesn't seem to support custom clipboard formats - bug #357642 // // IDataObject dataObject = Clipboard.GetDataObject (); // byte[] data = dataObject == null ? null : dataObject.GetData (DT_DATA_FORMAT) as byte[]; // if (data != null) { // MemoryStream stream = new MemoryStream (data); // stateSerializer.Deserialize (new BinaryFormatter().Deserialize (stream)); // ..... // } // if (_clipboard == null) { return; } DesignerTransaction transaction = host.CreateTransaction("Paste"); ICollection components = stateSerializer.Deserialize(_clipboard); // Console.WriteLine ("Pasted components: "); // foreach (object c in components) // Console.WriteLine (((IComponent)c).Site.Name); foreach (object component in components) { Control control = component as Control; if (control == null) { continue; // pure Components are added to the ComponentTray by the DocumentDesigner } PropertyDescriptor parentProperty = TypeDescriptor.GetProperties(control)["Parent"]; if (control.Parent != null) { // Already parented during deserialization? // In that case explicitly raise component changing/ed for the Parent property, // so it get's cought by the UndoEngine if (changeService != null) { changeService.OnComponentChanging(control, parentProperty); changeService.OnComponentChanged(control, parentProperty, null, control.Parent); } } else { ParentControlDesigner parentDesigner = null; if (selection != null && selection.PrimarySelection != null) { parentDesigner = host.GetDesigner((IComponent)selection.PrimarySelection) as ParentControlDesigner; } if (parentDesigner == null) { parentDesigner = host.GetDesigner(host.RootComponent) as DocumentDesigner; } if (parentDesigner != null && parentDesigner.CanParent(control)) { parentProperty.SetValue(control, parentDesigner.Control); } } } _clipboard = null; transaction.Commit(); ((IDisposable)transaction).Dispose(); }
/// <summary> /// Called by the framework when the designer is being initialized with the designed control /// </summary> /// <param name="component"></param> public override void Initialize(IComponent component) { base.Initialize(component); if (Control is TreeView) { try { m_oSelectionService = (ISelectionService) GetService(typeof (ISelectionService)); } catch { } try { m_oSelectionService.SelectionChanged += new EventHandler(this.OnSelectionServiceChanged); } catch { } try { m_oDesignerHost = (IDesignerHost) GetService(typeof (IDesignerHost)); } catch { } try { m_oMenuService = (IMenuCommandService) GetService(typeof (IMenuCommandService)); } catch { } try { m_oDesignerSerializationService = (IDesignerSerializationService) GetService(typeof (IDesignerSerializationService)); } catch { } try { m_oToolboxService = (IToolboxService) GetService(typeof (IToolboxService)); } catch { } try { m_oUIService = (IUIService) GetService(typeof (IUIService)); } catch { } try { m_oComponentChangeService = (IComponentChangeService) GetService(typeof (IComponentChangeService)); } catch { } m_oTreeView = (TreeView) Control; m_oTreeView.m_bFocus = true; m_oTreeView.ClearAllSelection(); m_oTreeView.DesignerHost = m_oDesignerHost; m_oTreeView.IsDesignMode = true; if (m_bFirstTime == true) { OnComponentCreated(m_oTreeView); m_bFirstTime = false; } try { m_oComponentAddedHandler = new ComponentEventHandler(this.OnComponentAdded); } catch { } try { m_oComponentRemovingHandler = new ComponentEventHandler(this.OnComponentRemoving); } catch { } try { m_oComponentChangeService.ComponentAdded += m_oComponentAddedHandler; } catch { } try { m_oComponentChangeService.ComponentRemoving += m_oComponentRemovingHandler; } catch { } try { m_oNodeParentChanged = new EventHandler(this.OnNodeParentChanged); } catch { } try { m_oOldCmdCopy = m_oMenuService.FindCommand(StandardCommands.Copy); } catch { } try { m_oOldCmdPaste = m_oMenuService.FindCommand(StandardCommands.Paste); } catch { } try { m_oOldCmdCut = m_oMenuService.FindCommand(StandardCommands.Cut); } catch { } try { m_oOldBringFront = m_oMenuService.FindCommand(StandardCommands.BringToFront); } catch { } try { m_oOldSendBack = m_oMenuService.FindCommand(StandardCommands.SendToBack); } catch { } try { m_oOldAlignGrid = m_oMenuService.FindCommand(StandardCommands.AlignToGrid); } catch { } try { m_oOldLockControls = m_oMenuService.FindCommand(StandardCommands.LockControls); } catch { } try { m_oOldDelete = m_oMenuService.FindCommand(StandardCommands.Delete); } catch { } try { m_oNewCmdCopy = new MenuCommand(new EventHandler(this.OnMenuCopy), StandardCommands.Copy); } catch { } try { m_oNewCmdPaste = new MenuCommand(new EventHandler(this.OnMenuPaste), StandardCommands.Paste); } catch { } if (TreeViewDesigner.MenuAdded == false) { try { m_oMenuService.RemoveCommand(m_oOldCmdCopy); } catch { } try { m_oMenuService.RemoveCommand(m_oOldCmdPaste); } catch { } try { m_oMenuService.AddCommand(m_oNewCmdCopy); } catch { } try { m_oMenuService.AddCommand(m_oNewCmdPaste); } catch { } TreeViewDesigner.MenuAdded = true; } m_oTreeView.Invalidate(); #region action menus #region node menu m_oActionMenuNode = new ActionMenuNative(); m_oActionMenuNode.Width = 170; m_oActionMenuNode.Title = "Node Action Menu"; ActionMenuGroup oMenuGroup = m_oActionMenuNode.AddMenuGroup("Editing"); oMenuGroup.Expanded = true; m_oActionMenuNode.AddMenuItem(oMenuGroup, "Add Node"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Delete Node"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Add Panel"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "-"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Clear Content"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Delete TreeView"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "-"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Copy"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Paste"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "-"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Properties"); oMenuGroup = m_oActionMenuNode.AddMenuGroup("Arranging"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Expand"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Collapse"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Top"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Bottom"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Up"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Down"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Left"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Right"); oMenuGroup = m_oActionMenuNode.AddMenuGroup("Color Schemes"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Default"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Forest"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Gold"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Ocean"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Rose"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Silver"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Sky"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Sunset"); m_oActionMenuNode.AddMenuItem(oMenuGroup, "Wood"); m_oActionMenuNode.ItemClick += new ActionMenuNative.ItemClickEventHandler(this.OnActionMenuNodeItemClicked); #endregion #region TreeView menu m_oActionMenuTreeView = new ActionMenuNative(); m_oActionMenuTreeView.Width = 170; m_oActionMenuTreeView.Title = "TreeView Action Menu"; oMenuGroup = m_oActionMenuTreeView.AddMenuGroup("Editing"); oMenuGroup.Expanded = true; m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Add Node"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Color Scheme Picker..."); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "-"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Clear Content"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Delete TreeView"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "-"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Copy"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Paste"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "-"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Properties"); oMenuGroup = m_oActionMenuTreeView.AddMenuGroup("Arranging"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Expand All"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Collapse All"); oMenuGroup = m_oActionMenuTreeView.AddMenuGroup("Layout"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Bring to Front"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Send to Back"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Align to Grid"); m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Lock Controls"); m_oActionMenuTreeView.ItemClick += new ActionMenuNative.ItemClickEventHandler(this.OnActionMenuTreeViewItemClicked); #endregion #endregion // enable the drag drop operations m_oTreeView.AllowDrop = true; this.EnableDragDrop(true); m_oTreeView.CollapseAll(); m_oSelector.SelectionService = m_oSelectionService; m_oSelector.TreeView = m_oTreeView; } }
/// <summary> /// 粘贴 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void Paste(object sender, EventArgs args) { IDesignerSerializationService serialService = this.GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService; IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost; ISelectionService selection = GetService(typeof(ISelectionService)) as ISelectionService; IComponentChangeService changeService = GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (host == null || serialService == null || clipboardData == null) { return; } //从获取上次剪切/复制的数据并反序列化 ICollection components = serialService.Deserialize(clipboardData); //如果当前选中的控件是容器控件则添加到容器中 //否则添加到根设计器中 if (components != null && components.Count > 0) { DesignerTransaction transaction = host.CreateTransaction("Paste"); foreach (Component item in components) { Control control = item as Control; if (control == null) { continue; } //if (control is IDBColProperty) //{ // (control as IDBColProperty).DBColName = string.Empty; //} PropertyDescriptor parentProperty = TypeDescriptor.GetProperties(control)["Parent"]; //获取粘贴到的父容器 ParentControlDesigner parentDesigner = null; if (selection != null && selection.PrimarySelection != null) { parentDesigner = host.GetDesigner((IComponent)selection.PrimarySelection) as ParentControlDesigner; } if (parentDesigner == null) { parentDesigner = host.GetDesigner(host.RootComponent) as DocumentDesigner; } if (parentDesigner != null && parentDesigner.CanParent(control)) { //粘贴时粘贴到父容器中间 //control.Location = new Point(parentDesigner.Control.Width / 2 - control.Width / 2, parentDesigner.Control.Height / 2 - control.Height / 2); parentProperty.SetValue(control, parentDesigner.Control); } } clipboardData = null; transaction.Commit(); ((IDisposable)transaction).Dispose(); selection.SetSelectedComponents(components); this.GlobalInvoke(StandardCommands.BringToFront); } }
protected virtual bool CanDropDataObject(IDataObject dataObj) { if (dataObj != null) { if (dataObj is ComponentDataObjectWrapper) { object[] dragObjs = GetDraggingObjects(dataObj, true); if (dragObjs == null) { return(false); } bool dropOk = true; for (int i = 0; dropOk && i < dragObjs.Length; i++) { dropOk = dropOk && (dragObjs[i] is IComponent) && client.IsDropOk((IComponent)dragObjs[i]); } return(dropOk); } try { object serializationData = dataObj.GetData(DataFormat, false); if (serializationData == null) { return(false); } IDesignerSerializationService ds = (IDesignerSerializationService)GetService(typeof(IDesignerSerializationService)); if (ds == null) { return(false); } ICollection objects = ds.Deserialize(serializationData); if (objects.Count > 0) { bool dropOk = true; foreach (object o in objects) { if (!(o is IComponent)) { continue; } dropOk = dropOk && client.IsDropOk((IComponent)o); if (!dropOk) { break; } } return(dropOk); } } catch (Exception ex) { // we return false on any exception if (ClientUtils.IsCriticalException(ex)) { throw; } } } return(false); }
private object OnCreateService(IServiceContainer container, System.Type serviceType) { if (serviceType == typeof(ISelectionService)) { if (this.selectionService == null) { this.selectionService = new SampleSelectionService(this); } return this.selectionService; } if (serviceType == typeof(IDesignerSerializationService)) { if (this.designerSerialService == null) { this.designerSerialService = new DesignerSerializationService(this); } return this.designerSerialService; } if (serviceType == typeof(ITypeDescriptorFilterService)) { return new SampleTypeDescriptorFilterService(this); } if (serviceType == typeof(IToolboxService)) { if (this.toolboxService == null) { this.toolboxService = new SampleToolboxService(this); } return this.toolboxService; } if (serviceType == typeof(IMenuCommandService)) { if (this.menuCommandService == null) { this.menuCommandService = new SampleMenuCommandService(this); } return this.menuCommandService; } Debug.Fail("Service type " + serviceType.FullName + " requested but we don't support it"); return null; }