|
private void Form1_Load(object sender, EventArgs e)
{
…
// Récupération du service ISelectionService
System.ComponentModel.Design.ISelectionService selectionService =
(System.ComponentModel.Design.ISelectionService) designer.GetService(typeof(System.ComponentModel.Design.ISelectionService));
// Add the evenement SelectionChanged
selectionService.SelectionChanged += new EventHandler(selectionService_SelectionChanged);
// Assocation the control container to the propertyGrid
propertyGrid1.SelectedObject = host.RootComponent;
}
void selectionService_SelectionChanged(object sender, EventArgs e)
{
System.ComponentModel.Design.ISelectionService selectionService = (System.ComponentModel.Design.ISelectionService)sender;
// Creation of the list of controls sélectionned
IComponent[] listSelection = new IComponent[selectionService.SelectionCount];
selectionService.GetSelectedComponents().CopyTo(listSelection, 0);
// Association the controls selected to the propertyGrid
propertyGrid1.SelectedObjects = listSelection;
}
// Release the ressources
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Release the evenements on the service of IComponentChangeService System.ComponentModel.Design.ISelectionService selectionService =
(System.ComponentModel.Design.ISelectionService)
designer.GetService(typeof(System.ComponentModel.Design.ISelectionService));
selectionService.SelectionChanged -= new EventHandler(selectionService_SelectionChanged);
// Delete the view of designer of panel
panel1.Controls.Remove((Control)designer.View);
// Release the designer to the form
designer.Dispose();
} |