ComponentEditorPage Class
Provides a base implementation for a ComponentEditorPage.
For a list of all members of this type, see ComponentEditorPage Members.
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.Panel
System.Windows.Forms.Design.ComponentEditorPage
[Visual Basic] MustInherit Public Class ComponentEditorPage Inherits Panel [C#] public abstract class ComponentEditorPage : Panel [C++] public __gc __abstract class ComponentEditorPage : public Panel [JScript] public abstract class ComponentEditorPage extends Panel
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
ComponentEditorPage is a complete implementation for a component editor page that consists of an empty window. You can extend this page to add your own controls. ComponentEditorPage is used by a ComponentEditorForm of a WindowsFormsComponentEditor.
Example
[Visual Basic, C#, C++] The following code example demonstrates an example ComponentEditorPage implementation.
[Visual Basic] ' This example component editor page type provides an example ' ComponentEditorPage implementation. Friend Class ExampleComponentEditorPage Inherits System.Windows.Forms.Design.ComponentEditorPage Private l1 As Label Private b1 As Button Private pg1 As PropertyGrid ' Base64-encoded serialized image data for the required component editor page icon. Private icondata As String = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuNTAwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABNTeXN0ZW0uRHJhd2luZy5JY29uAgAAAAhJY29uRGF0YQhJY29uU2l6ZQcEAhNTeXN0ZW0uRHJhd2luZy5TaXplAgAAAAIAAAAJAwAAAAX8////E1N5c3RlbS5EcmF3aW5nLlNpemUCAAAABXdpZHRoBmhlaWdodAAACAgCAAAAAAAAAAAAAAAPAwAAAD4BAAACAAABAAEAEBAQAAAAAAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgADExAAAgICAAMDAwAA+iPcAY77gACh9kwD/AAAAndPoADpw6wD///8AAAAAAAAAAAAHd3d3d3d3d8IiIiIiIiLHKIiIiIiIiCco///////4Jyj5mfIvIvgnKPnp////+Cco+en7u7v4Jyj56f////gnKPmZ8i8i+Cco///////4JyiIiIiIiIgnJmZmZmZmZifCIiIiIiIiwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACw==" Public Sub New() ' Initialize the page, which inherits from Panel, and its controls. Me.Size = New Size(400, 250) Me.Icon = DeserializeIconFromBase64Text(icondata) Me.Text = "Example Page" b1 = New Button b1.Size = New Size(200, 20) b1.Location = New Point(200, 0) b1.Text = "Set a random background color" AddHandler b1.Click, AddressOf Me.randomBackColor Me.Controls.Add(b1) l1 = New Label l1.Size = New Size(190, 20) l1.Location = New Point(4, 2) l1.Text = "Example Component Editor Page" Me.Controls.Add(l1) pg1 = New PropertyGrid pg1.Size = New Size(400, 280) pg1.Location = New Point(0, 30) Me.Controls.Add(pg1) End Sub ' This method indicates that the Help button should be enabled for this ' component editor page. Public Overrides Function SupportsHelp() As Boolean Return True End Function ' 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 Overrides Sub ShowHelp() ' The GetSelectedComponent method of a ComponentEditorPage retrieves the ' IComponent associated with the WindowsFormsComponentEditor. Dim selectedComponent As IComponent = Me.GetSelectedComponent() ' Retrieve the Site of the component, and return if null. Dim componentSite As ISite = selectedComponent.Site If componentSite Is Nothing Then Return End If ' Acquire the IHelpService to display a help topic using a indexed keyword lookup. Dim helpService As IHelpService = CType(componentSite.GetService(GetType(IHelpService)), IHelpService) If Not (helpService Is Nothing) Then helpService.ShowHelpFromKeyword("System.Windows.Forms.ComboBox") End If End Sub ' The LoadComponent method is raised when the ComponentEditorPage is displayed. Protected Overrides Sub LoadComponent() Me.pg1.SelectedObject = Me.Component End Sub ' The SaveComponent method is raised when the WindowsFormsComponentEditor is closing ' or the current ComponentEditorPage is closing. Protected Overrides Sub SaveComponent() End Sub ' 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. Private Sub randomBackColor(ByVal sender As Object, ByVal e As EventArgs) If GetType(System.Windows.Forms.Control).IsAssignableFrom(CType(Me.Component, Object).GetType()) Then ' Sets the background color of the Control associated with the ' WindowsFormsComponentEditor to a random color. Dim rnd As New Random CType(Me.Component, System.Windows.Forms.Control).BackColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)) pg1.Refresh() End If End Sub ' This method can be used to retrieve an Icon from a block ' of Base64-encoded text. Private Function DeserializeIconFromBase64Text(ByVal [text] As String) As icon Dim img As Icon = Nothing Dim memBytes As Byte() = Convert.FromBase64String([text]) Dim formatter = New BinaryFormatter Dim stream As New MemoryStream(memBytes) img = CType(formatter.Deserialize(stream), Icon) stream.Close() Return img End Function End Class [C#] // This example component editor page type provides an example // ComponentEditorPage implementation. internal class ExampleComponentEditorPage : System.Windows.Forms.Design.ComponentEditorPage { Label l1; Button b1; PropertyGrid pg1; // Base64-encoded serialized image data for the required component editor page icon. string icon = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuNTAwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABNTeXN0ZW0uRHJhd2luZy5JY29uAgAAAAhJY29uRGF0YQhJY29uU2l6ZQcEAhNTeXN0ZW0uRHJhd2luZy5TaXplAgAAAAIAAAAJAwAAAAX8////E1N5c3RlbS5EcmF3aW5nLlNpemUCAAAABXdpZHRoBmhlaWdodAAACAgCAAAAAAAAAAAAAAAPAwAAAD4BAAACAAABAAEAEBAQAAAAAAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgADExAAAgICAAMDAwAA+iPcAY77gACh9kwD/AAAAndPoADpw6wD///8AAAAAAAAAAAAHd3d3d3d3d8IiIiIiIiLHKIiIiIiIiCco///////4Jyj5mfIvIvgnKPnp////+Cco+en7u7v4Jyj56f////gnKPmZ8i8i+Cco///////4JyiIiIiIiIgnJmZmZmZmZifCIiIiIiIiwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACw=="; public ExampleComponentEditorPage() { // Initialize the page, which inherits from Panel, and its controls. this.Size = new Size( 400, 250 ); this.Icon = DeserializeIconFromBase64Text(icon); this.Text = "Example Page"; b1 = new Button(); b1.Size = new Size(200, 20); b1.Location = new Point(200, 0); b1.Text = "Set a random background color"; b1.Click += new EventHandler(this.randomBackColor); this.Controls.Add( b1 ); l1 = new Label(); l1.Size = new Size(190, 20); l1.Location = new Point(4, 2); l1.Text = "Example Component Editor Page"; this.Controls.Add( l1 ); pg1 = new PropertyGrid(); pg1.Size = new Size(400, 280); pg1.Location = new Point(0,30); this.Controls.Add( pg1 ); } // This method indicates that the Help button should be enabled for this // component editor page. public override bool SupportsHelp() { return 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 = this.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)); if (helpService != null) helpService.ShowHelpFromKeyword("System.Windows.Forms.ComboBox"); } // The LoadComponent method is raised when the ComponentEditorPage is displayed. protected override void LoadComponent() { this.pg1.SelectedObject = this.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. private void randomBackColor(object sender, EventArgs e) { if( typeof(System.Windows.Forms.Control).IsAssignableFrom( this.Component.GetType() ) ) { // Sets the background color of the Control associated with the // WindowsFormsComponentEditor to a random color. Random rnd = new Random(); ((System.Windows.Forms.Control)this.Component).BackColor = Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)); pg1.Refresh(); } } // This method can be used to retrieve an Icon from a block // of Base64-encoded text. private Icon DeserializeIconFromBase64Text(string text) { Icon img = null; byte[] memBytes = Convert.FromBase64String(text); IFormatter formatter = new BinaryFormatter(); MemoryStream stream = new MemoryStream(memBytes); img = (Icon)formatter.Deserialize(stream); stream.Close(); return img; } } [C++] // This example component editor page type provides an example // ComponentEditorPage implementation. private __gc class ExampleComponentEditorPage : public System::Windows::Forms::Design::ComponentEditorPage { Label* l1; Button* b1; PropertyGrid* pg1; // Base64-encoded serialized image data for the required component editor page icon. String* icon; public: ExampleComponentEditorPage() { String* temp = S"AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuNTAwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABNTeXN0ZW0uRHJhd2luZy5JY29uAgAAAAhJY29uRGF0Y" S"QhJY29uU2l6ZQcEAhNTeXN0ZW0uRHJhd2luZy5TaXplAgAAAAIAAAAJAwAAAAX8////E1N5c3RlbS5EcmF3aW5nLlNpemUCAAAABXdpZHRoBmhlaWdodAAACAgCAAAAAAAAAAAAAAAPAwAAAD4BAAACAAABAAEAEBAQAAAAAAAoAQAAFgAAACgAAAAQAAAAIA" S"AAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgADExAAAgICAAMDAwAA+iPcAY77gACh9kwD/AAAAndPoADpw6wD///8AAAAAAAAAAAAHd3d3d3d3d8IiIiIiIiLHKIiIiIiIiCco///////4Jyj5mfIvIvgnKPn" S"p////+Cco+en7u7v4Jyj56f////gnKPmZ8i8i+Cco///////4JyiIiIiIiIgnJmZmZmZmZifCIiIiIiIiwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACw=="; icon = temp; // Initialize the page, which inherits from Panel, and its controls. this->Size = System::Drawing::Size( 400, 250 ); this->Icon = DeserializeIconFromBase64Text(icon); this->Text = S"Example Page"; b1 = new Button(); b1->Size = System::Drawing::Size(200, 20); b1->Location = Point(200, 0); b1->Text = S"Set a random background color"; b1->Click += new EventHandler(this, &ExampleComponentEditorPage::randomBackColor); this->Controls->Add( b1 ); l1 = new Label(); l1->Size = System::Drawing::Size(190, 20); l1->Location = Point(4, 2); l1->Text = S"Example Component Editor Page"; this->Controls->Add( l1 ); pg1 = new PropertyGrid(); pg1->Size = System::Drawing::Size(400, 280); pg1->Location = Point(0,30); this->Controls->Add( pg1 ); } // This method indicates that the Help button should be enabled for this // component editor page. bool SupportsHelp() { return 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: void ShowHelp() { // The GetSelectedComponent method of a ComponentEditorPage retrieves the // IComponent associated with the WindowsFormsComponentEditor. IComponent* selectedComponent = this->GetSelectedComponent(); // Retrieve the Site of the component, and return if null. ISite* componentSite = selectedComponent->Site; if(componentSite == 0) return; // Acquire the IHelpService to display a help topic using a indexed keyword lookup. IHelpService* helpService = dynamic_cast<IHelpService*>(componentSite->GetService(__typeof(IHelpService))); if (helpService != 0) helpService->ShowHelpFromKeyword(S"System.Windows.Forms.ComboBox"); } // The LoadComponent method is raised when the ComponentEditorPage is displayed. protected: void LoadComponent() { this->pg1->SelectedObject = this->Component; } // The SaveComponent method is raised when the WindowsFormsComponentEditor is closing // or the current ComponentEditorPage is closing. 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. private: void randomBackColor(Object* /*sender*/, EventArgs* /*e*/) { if( __typeof(System::Windows::Forms::Control)->IsAssignableFrom( this->Component::GetType() ) ) { // Sets the background color of the Control associated with the // WindowsFormsComponentEditor to a random color. Random* rnd = new Random(); (dynamic_cast<System::Windows::Forms::Control*>(this->Component))->BackColor = Color::FromArgb(rnd->Next(255), rnd->Next(255), rnd->Next(255)); pg1->Refresh(); } } // This method can be used to retrieve an Icon from a block // of Base64-encoded text. System::Drawing::Icon* DeserializeIconFromBase64Text(String* text) { System::Drawing::Icon* img = 0; Byte memBytes[] = Convert::FromBase64String(text); IFormatter* formatter = new BinaryFormatter(); MemoryStream* stream = new MemoryStream(memBytes); img = dynamic_cast<System::Drawing::Icon*>(formatter->Deserialize(stream)); stream->Close(); return img; } };
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Windows.Forms.Design
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
See Also
ComponentEditorPage Members | System.Windows.Forms.Design Namespace | ComponentEditorForm | WindowsFormsComponentEditor