ObjectInfo FinishObjectCreation(Object obj) { // Generate a name if (obj is Control && !_asyncObjectCreation) { Control c = (Control)obj; c.Name = CompNumber.GetCompName(obj.GetType()); // This one can't have the text set to anything but a date if (!(c is DateTimePicker)) { c.Text = c.Name; } } ObjectInfo objInfo = _targetNode.AddNewObject(obj, _sourceNode); // This is the case when the control is created not by dragging // it to the design panel, but dragging it to the object // tree somewhere if (_sourceNode is IDesignSurfaceNode) { IDesignSurfaceNode dNode = (IDesignSurfaceNode)_sourceNode; if (obj is Control) { Control control = (Control)obj; // Some of them don't have them, need to pick something // so its visible Size defaultSize; PropertyInfo p = typeof(Control).GetProperty("DefaultSize", ReflectionHelper.ALL_BINDINGS); defaultSize = (Size)p.GetValue(control, null); if (defaultSize.Equals(Size.Empty)) { TraceUtil.WriteLineWarning(this, "No DefaultSize specified for " + control); control.Size = new Size(200, 200); } if (dNode.OnDesignSurface) { // Give the user a change with AxWebBrowser if (control.GetType().Name.Equals("AxWebBrowser")) { ErrorDialog.Show ("Before calling methods on the WebBrowser " + "object, please turn off Design Mode. " + "This works around a known problem where " + "the browser control does not work " + "initially correctly in design mode. " + "The problem only occurs on the " + "first method invocation; you may turn on " + "design mode after the first method call " + "is completely finished.", "Please turn off Design Mode", MessageBoxIcon.Warning); } try { // The control may complain if it does not // like where it is being added ObjectBrowser.ImagePanel.AddControl(objInfo, control); } catch (Exception ex) { _targetNode.RemoveObject(objInfo.Obj); throw new Exception ("There was an error adding this control " + "to the design surface. You might want " + "using the Action menu (right-click) " + "to not have the control created " + "on the design surface", ex); } } control.Show(); } } return(objInfo); }