WindowsFormsComponentEditor 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供一個基底類別,供使用模態對話框顯示類似 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
- 繼承
- 衍生
範例
以下程式碼範例展示了一個實 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;
建構函式
| 名稱 | Description |
|---|---|
| WindowsFormsComponentEditor() |
初始化 WindowsFormsComponentEditor 類別的新執行個體。 |
方法
| 名稱 | Description |
|---|---|
| EditComponent(ITypeDescriptorContext, Object, IWin32Window) |
建立一個編輯器視窗,讓使用者可以編輯指定的元件。 |
| EditComponent(ITypeDescriptorContext, Object) |
建立一個編輯器視窗,讓使用者能使用指定的上下文資訊編輯指定的元件。 |
| EditComponent(Object, IWin32Window) |
建立一個編輯器視窗,讓使用者使用擁有該元件的指定視窗來編輯指定的元件。 |
| EditComponent(Object) |
編輯該元件並回傳一個值,表示該元件是否被修改。 (繼承來源 ComponentEditor) |
| Equals(Object) |
判斷指定的 物件是否等於目前的物件。 (繼承來源 Object) |
| GetComponentEditorPages() |
取得與該編輯器相關的元件編輯器頁面。 |
| GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
| GetInitialComponentEditorPageIndex() |
取得元件編輯器初始頁面的索引,供元件編輯器顯示。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |