/// <summary> /// Registers a control so it becomes visible as part of the main form</summary> /// <param name="control">Control</param> /// <param name="info">Control display information</param> /// <param name="client">Client that owns the control and receives notifications /// about its status, or null if no notifications are needed</param> /// <remarks>If IControlHostClient.Close() has been called, the IControlHostService /// also calls UnregisterControl. Call RegisterControl again to re-register the Control.</remarks> public void RegisterControl(Control control, ControlInfo info, IControlHostClient client) { if (control == null) throw new ArgumentNullException("control"); if (info == null) throw new ArgumentNullException("info"); if (FindControlInfo(control) != null) throw new ArgumentException("Control already registered"); // allow null client if (client == null) client = Global<DefaultClient>.Instance; info.Client = client; info.Control = control; info.Changed += info_Changed; var dockContent = new DockContent(this); if (!string.IsNullOrEmpty(info.HelpUrl)) dockContent.AddHelp(info.HelpUrl); // set persistence id one time only. // do not update dockContent.Name // dockContent.Text is used for titlebar. dockContent.Name = GetPersistenceId(info); UpdateDockContent(dockContent, info); m_dockContent.Add(info, dockContent); m_controls.ActiveItem = info; info.HostControl = dockContent; // Any property we set on this Control needs to be restored in UnregisterControl. // For example, QuadPanelControl was broken by setting Dock property but not restoring it. info.OriginalDock = control.Dock; control.Dock = DockStyle.Fill; dockContent.Controls.Add(control); dockContent.FormClosing += dockContent_FormClosing; ShowDockContent(dockContent, info); if (info.ShowInMenu) { if (info.IsDocument.HasValue && info.IsDocument.Value) { // description( and the tooltip) for a document control by convention is the full path of the document RegisterMenuCommand(info, "@" + info.Description); } else RegisterMenuCommand(info, "@" + dockContent.Text); // tells m_commandService not to interpret slashes as submenus } // Bring all the Controls for this client to the front. BringClientToFront(client); // Call the IControlHostClient's Activate method. Seems to be required when driving // the app from a script and if the user clicks on another app at the wrong moment. ActivateClient(control); }