本文整理汇总了C#中System.Drawing.Design.ToolboxItem.CreateComponents方法的典型用法代码示例。如果您正苦于以下问题:C# ToolboxItem.CreateComponents方法的具体用法?C# ToolboxItem.CreateComponents怎么用?C# ToolboxItem.CreateComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Design.ToolboxItem
的用法示例。
在下文中一共展示了ToolboxItem.CreateComponents方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetActivitiesFromToolboxItem
private static ICollection GetActivitiesFromToolboxItem(IServiceProvider serviceProvider, bool addAssemblyReference, IDesignerHost designerHost, ICollection activities, ToolboxItem toolBoxItem)
{
// this will make sure that we add the assembly reference to project
if (addAssemblyReference && toolBoxItem.AssemblyName != null)
{
ITypeResolutionService trs = serviceProvider.GetService(typeof(ITypeResolutionService)) as ITypeResolutionService;
if (trs != null)
trs.ReferenceAssembly(toolBoxItem.AssemblyName);
}
ActivityToolboxItem ActivityToolboxItem = toolBoxItem as ActivityToolboxItem;
if (addAssemblyReference && ActivityToolboxItem != null)
activities = ActivityToolboxItem.CreateComponentsWithUI(designerHost);
else
activities = toolBoxItem.CreateComponents(designerHost);
return activities;
}
示例2: CreateTool
public IComponent[] CreateTool(ToolboxItem tool, Control parent, int x, int y, int width, int height, bool hasLocation, bool hasSize, ToolboxSnapDragDropEventArgs e)
{
IToolboxService service = (IToolboxService) this.GetService(typeof(IToolboxService));
ISelectionService service2 = (ISelectionService) this.GetService(typeof(ISelectionService));
IDesignerHost host = (IDesignerHost) this.GetService(typeof(IDesignerHost));
IComponent[] c = new IComponent[0];
Cursor current = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
DesignerTransaction transaction = null;
try
{
try
{
if (host != null)
{
transaction = host.CreateTransaction(System.Design.SR.GetString("DesignerBatchCreateTool", new object[] { tool.ToString() }));
}
}
catch (CheckoutException exception)
{
if (exception != CheckoutException.Canceled)
{
throw exception;
}
return c;
}
try
{
try
{
if ((host != null) && this.CurrentlyLocalizing(host.RootComponent))
{
IUIService service3 = (IUIService) this.GetService(typeof(IUIService));
if (service3 != null)
{
service3.ShowMessage(System.Design.SR.GetString("LocalizingCannotAdd"));
}
return new IComponent[0];
}
Hashtable defaultValues = new Hashtable();
if (parent != null)
{
defaultValues["Parent"] = parent;
}
if ((parent != null) && parent.IsMirrored)
{
x += width;
}
if (hasLocation)
{
defaultValues["Location"] = new Point(x, y);
}
if (hasSize)
{
defaultValues["Size"] = new Size(width, height);
}
if (e != null)
{
defaultValues["ToolboxSnapDragDropEventArgs"] = e;
}
c = tool.CreateComponents(host, defaultValues);
}
catch (CheckoutException exception2)
{
if (exception2 != CheckoutException.Canceled)
{
throw;
}
c = new IComponent[0];
}
catch (ArgumentException exception3)
{
IUIService service4 = (IUIService) this.GetService(typeof(IUIService));
if (service4 != null)
{
service4.ShowError(exception3);
}
}
catch (Exception exception4)
{
IUIService service5 = (IUIService) this.GetService(typeof(IUIService));
string message = string.Empty;
if (exception4.InnerException != null)
{
message = exception4.InnerException.ToString();
}
if (string.IsNullOrEmpty(message))
{
message = exception4.ToString();
}
if (exception4 is InvalidOperationException)
{
message = exception4.Message;
}
if (service5 == null)
{
throw;
}
service5.ShowError(exception4, System.Design.SR.GetString("FailedToCreateComponent", new object[] { tool.DisplayName, message }));
}
//.........这里部分代码省略.........
示例3: CreateToolCore
// Creates a component from a ToolboxItem, sets its location and size if available and snaps it's
// location to the grid.
//
protected virtual IComponent[] CreateToolCore (ToolboxItem tool, int x, int y, int width, int height,
bool hasLocation, bool hasSize)
{
if (tool == null)
throw new ArgumentNullException ("tool");
IDesignerHost host = GetService (typeof (IDesignerHost)) as IDesignerHost;
DesignerTransaction transaction = host.CreateTransaction ("Create components in tool '" + tool.DisplayName + "'");
IComponent[] components = tool.CreateComponents (host);
foreach (IComponent component in components)
{
ControlDesigner controlDesigner = host.GetDesigner (component) as ControlDesigner;
if (controlDesigner == null) { // not a Control, but e.g. a plain Component
continue;
} else if (!this.CanParent (controlDesigner)) {
host.DestroyComponent (component);
continue;
}
Control control = component as Control;
if (control != null) {
this.Control.SuspendLayout ();
// set parent instead of controls.Add so that it gets serialized for Undo/Redo
TypeDescriptor.GetProperties (control)["Parent"].SetValue (control, this.Control);
this.Control.SuspendLayout ();
if (hasLocation)
base.SetValue (component, "Location", this.SnapPointToGrid (new Point (x, y)));
else
base.SetValue (component, "Location", this.SnapPointToGrid (this.DefaultControlLocation));
if (hasSize)
base.SetValue (component, "Size", new Size (width, height));
this.Control.Refresh ();
}
}
ISelectionService selectionServ = this.GetService (typeof (ISelectionService)) as ISelectionService;
if (selectionServ != null)
selectionServ.SetSelectedComponents (components, SelectionTypes.Replace);
transaction.Commit ();
return components;
}
示例4: GetActivitiesFromToolboxItem
private static ICollection GetActivitiesFromToolboxItem(IServiceProvider serviceProvider, bool addAssemblyReference, IDesignerHost designerHost, ICollection activities, ToolboxItem toolBoxItem)
{
if (addAssemblyReference && (toolBoxItem.AssemblyName != null))
{
ITypeResolutionService service = serviceProvider.GetService(typeof(ITypeResolutionService)) as ITypeResolutionService;
if (service != null)
{
service.ReferenceAssembly(toolBoxItem.AssemblyName);
}
}
ActivityToolboxItem item = toolBoxItem as ActivityToolboxItem;
if (addAssemblyReference && (item != null))
{
activities = item.CreateComponentsWithUI(designerHost);
return activities;
}
activities = toolBoxItem.CreateComponents(designerHost);
return activities;
}
示例5: CreateToolCore
// Creates a component from a ToolboxItem, sets its location and size if available and snaps it's
// location to the grid.
//
protected virtual IComponent[] CreateToolCore (ToolboxItem tool, int x, int y, int width, int height,
bool hasLocation, bool hasSize)
{
if (tool == null)
throw new ArgumentNullException ("tool");
IDesignerHost host = GetService (typeof (IDesignerHost)) as IDesignerHost;
IComponent[] components = tool.CreateComponents (host);
foreach (IComponent component in components)
{
Control control = component as Control;
if (control != null) {
if (hasLocation)
base.SetValue (component, "Location", this.SnapPointToGrid (new Point (x, y)));
else
base.SetValue (component, "Location", this.SnapPointToGrid (this.DefaultControlLocation));
if (hasSize)
base.SetValue (component, "Size", new Size (width, height));
this.Control.SuspendLayout ();
this.Control.Controls.Add (control);
this.Control.SuspendLayout ();
this.Control.Refresh ();
}
}
ISelectionService selectionServ = this.GetService (typeof (ISelectionService)) as ISelectionService;
if (selectionServ != null)
selectionServ.SetSelectedComponents (components, SelectionTypes.Replace);
return components;
}