-
Notifications
You must be signed in to change notification settings - Fork 263
ControlHostService Component
The ControlHostService
component is responsible for exposing client controls in the application's main form. The control host service allows the client to specify a preferred location for the main form, and calls the client back when the control gets or loses focus, or is closed by the user. This component also provides a dock in which to hold controls, such as menus and tool strips. The docking control allows moving windows around on the dock. The window configuration can be saved, using the components WindowLayoutService
and WindowLayoutServiceCommands
.
ControlHostService
implements the IControlHostService
interface. IControlHostService
offers methods similar to ICommandService
. IControlHostService
offers methods to register, unregister, and show controls, instead of commands.
ControlHostService
also implements IControlRegistry
, which tracks active controls, noting when controls are activated or deactivated. For more information, see Using Controls in ATF.
The ControlHostService
component, or one like it, is useful to any application that has a GUI and is used by nearly all the ATF samples. Because it is a component, applications simply need to add ControlHostService
to the MEF TypeCatalog
. Applications also need to add the CommandService
and SettingsService
components, because ControlHostService
imports ICommandService
and ISettingsService
.
For WinForms, ControlHostService
also imports IContextMenuCommandProvider
, which is used for getting a list of commands to present on a context menu. IContextMenuCommandProvider
is imported using an [ImportMany]
attribute, and you don't have to provide such an import for ControlHostService
to work. This import is provided in case there are any controls in the application that have context menus.
For more information on satisfying components' import needs, see Using ATF Components.
There are versions of ControlHostService
and IControlHostService
for both WinForms and WPF.
For more information, see Using Controls in ATF.
Here is a simple example of creating and registering a control from the PaletteService
component. The call to RegisterControl()
uses the ControlInfo
class, which describes the control in the UI. This class is analogous to the CommandInfo
class for commands, and it provides information on the control, such as a text description ("Palette").
m_control = new UserControl();
m_control.Dock = DockStyle.Fill;
m_control.SuspendLayout();
m_control.Name = "Palette".Localize();
m_control.Text = "Palette".Localize();
m_control.Controls.Add(m_searchInput);
m_control.Controls.Add(TreeControl);
m_control.Layout += controls_Layout;
m_control.ResumeLayout();
m_controlHostService.RegisterControl(
m_control,
new ControlInfo(
"Palette".Localize(),
"Creates new instances".Localize(),
StandardControlGroup.Left),
this);
To learn more, see Registering Controls.
ATF Application Basics and Services
-
WinForms Application: Show a
Main()
function pattern common in WinForms application ATF samples and what it accomplishes. - WPF Application: Discuss how WPF applications differ from WinForms ones in basic application structure.
- ControlHostService Component: This component is responsible for exposing client Controls in the application's main form.
- CommandService Component: Show the basics of supporting commands in ATF.
- SettingsService Component: This component manages preferences and their persistence.
- StatusService Component: Show how to use this component to display status messages.
- Other ATF Services: Describe other services: document management, file dialogs, Help dialog, and resources.
- Home
- Getting Started
- Features & Benefits
- Requirements & Dependencies
- Gallery
- Technology & Samples
- Adoption
- News
- Release Notes
- ATF Community
- Searching Documentation
- Using Documentation
- Videos
- Tutorials
- How To
- Programmer's Guide
- Reference
- Code Samples
- Documentation Files
© 2014-2015, Sony Computer Entertainment America LLC