WindowsFormsComponentEditor Classe
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Fornece uma classe base para editores que usam uma caixa de diálogo modal para exibir uma página de propriedades semelhante à página de propriedades de um controle ActiveX.
public ref class WindowsFormsComponentEditor abstract : System::ComponentModel::ComponentEditor
public abstract class WindowsFormsComponentEditor : System.ComponentModel.ComponentEditor
type WindowsFormsComponentEditor = class
inherit ComponentEditor
Public MustInherit Class WindowsFormsComponentEditor
Inherits ComponentEditor
- Herança
- Derivado
Exemplos
O exemplo de código a seguir demonstra uma implementação de exemplo WindowsFormsComponentEditor .
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
// This example demonstrates how to implement a component editor that hosts
// component pages and associate it with a component. This example also
// demonstrates how to implement a component page that provides a panel-based
// control system and Help keyword support.
// The ExampleComponentEditor displays two ExampleComponentEditorPage pages.
public class ExampleComponentEditor : WindowsFormsComponentEditor
{
// This method override returns an type array containing the type of
// each component editor page to display.
protected override Type[] GetComponentEditorPages() => [typeof(ExampleComponentEditorPage), typeof(ExampleComponentEditorPage)];
// This method override returns the index of the page to display when the
// component editor is first displayed.
protected override int GetInitialComponentEditorPageIndex() => 1;
}
// This example component editor page type provides an example
// ComponentEditorPage implementation.
class ExampleComponentEditorPage : ComponentEditorPage
{
readonly Label _l1;
readonly Button b1;
readonly PropertyGrid pg1;
public ExampleComponentEditorPage()
{
// Initialize the page, which inherits from Panel, and its controls.
Size = new Size(400, 250);
Icon = new Icon("myicon.ico");
Text = "Example Page";
b1 = new Button
{
Size = new Size(200, 20),
Location = new Point(200, 0),
Text = "Set a random background color"
};
b1.Click += randomBackColor;
Controls.Add(b1);
_l1 = new Label
{
Size = new Size(190, 20),
Location = new Point(4, 2),
Text = "Example Component Editor Page"
};
Controls.Add(_l1);
pg1 = new PropertyGrid
{
Size = new Size(400, 280),
Location = new Point(0, 30)
};
Controls.Add(pg1);
}
// This method indicates that the Help button should be enabled for this
// component editor page.
public override bool SupportsHelp() => true;
// This method is called when the Help button for this component editor page is pressed.
// This implementation uses the IHelpService to show the Help topic for a sample keyword.
public override void ShowHelp()
{
// The GetSelectedComponent method of a ComponentEditorPage retrieves the
// IComponent associated with the WindowsFormsComponentEditor.
IComponent selectedComponent = GetSelectedComponent();
// Retrieve the Site of the component, and return if null.
ISite componentSite = selectedComponent.Site;
if (componentSite == null)
{
return;
}
// Acquire the IHelpService to display a help topic using a indexed keyword lookup.
IHelpService helpService = (IHelpService)componentSite.GetService(typeof(IHelpService));
helpService?.ShowHelpFromKeyword("System.Windows.Forms.ComboBox");
}
// The LoadComponent method is raised when the ComponentEditorPage is displayed.
protected override void LoadComponent() => pg1.SelectedObject = Component;
// The SaveComponent method is raised when the WindowsFormsComponentEditor is closing
// or the current ComponentEditorPage is closing.
protected override void SaveComponent()
{
}
// If the associated component is a Control, this method sets the BackColor to a random color.
// This method is invoked by the button on this ComponentEditorPage.
void randomBackColor(object sender, EventArgs e)
{
if (typeof(Control).IsAssignableFrom(Component.GetType()))
{
// Sets the background color of the Control associated with the
// WindowsFormsComponentEditor to a random color.
Random rnd = new();
((Control)Component).BackColor =
Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255));
pg1.Refresh();
}
}
}
// This example control is associated with the ExampleComponentEditor
// through the following EditorAttribute.
[Editor(typeof(ExampleComponentEditor), typeof(ComponentEditor))]
public class ExampleUserControl : UserControl;
Construtores
| Nome | Description |
|---|---|
| WindowsFormsComponentEditor() |
Inicializa uma nova instância da classe WindowsFormsComponentEditor. |
Métodos
| Nome | Description |
|---|---|
| EditComponent(ITypeDescriptorContext, Object, IWin32Window) |
Cria uma janela do editor que permite ao usuário editar o componente especificado. |
| EditComponent(ITypeDescriptorContext, Object) |
Cria uma janela do editor que permite que o usuário edite o componente especificado usando as informações de contexto especificadas. |
| EditComponent(Object, IWin32Window) |
Cria uma janela do editor que permite ao usuário editar o componente especificado usando a janela especificada que possui o componente. |
| EditComponent(Object) |
Edita o componente e retorna um valor que indica se o componente foi modificado. (Herdado de ComponentEditor) |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
| GetComponentEditorPages() |
Obtém as páginas do editor de componentes associadas ao editor de componentes. |
| GetHashCode() |
Serve como a função hash predefinida. (Herdado de Object) |
| GetInitialComponentEditorPageIndex() |
Obtém o índice da página inicial do editor de componentes para exibição do editor de componentes. |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Objectatual. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual. (Herdado de Object) |