แก้ไข

แชร์ผ่าน


WebPartChrome.CreateWebPartChromeStyle(WebPart, PartChromeType) Method

Definition

Creates the style object that supplies style attributes for each WebPart control rendered by the WebPartChrome object.

protected:
 virtual System::Web::UI::WebControls::Style ^ CreateWebPartChromeStyle(System::Web::UI::WebControls::WebParts::WebPart ^ webPart, System::Web::UI::WebControls::WebParts::PartChromeType chromeType);
protected virtual System.Web.UI.WebControls.Style CreateWebPartChromeStyle (System.Web.UI.WebControls.WebParts.WebPart webPart, System.Web.UI.WebControls.WebParts.PartChromeType chromeType);
abstract member CreateWebPartChromeStyle : System.Web.UI.WebControls.WebParts.WebPart * System.Web.UI.WebControls.WebParts.PartChromeType -> System.Web.UI.WebControls.Style
override this.CreateWebPartChromeStyle : System.Web.UI.WebControls.WebParts.WebPart * System.Web.UI.WebControls.WebParts.PartChromeType -> System.Web.UI.WebControls.Style
Protected Overridable Function CreateWebPartChromeStyle (webPart As WebPart, chromeType As PartChromeType) As Style

Parameters

webPart
WebPart

The control that is currently being rendered.

chromeType
PartChromeType

The type of chrome for a particular control; one of the PartChromeType enumeration values.

Returns

A Style that contains style attributes for the webPart.

Exceptions

webPart is null.

chromeType is not one of the PartChromeType enumeration values.

Examples

This code example demonstrates use of the CreateWebPartChromeStyle method. For the full code required to run the example, see the Example section of the WebPartChrome class overview topic.

The following section from the code example demonstrates how to override the CreateWebPartChromeStyle method. Notice that it first retrieves the style information created by the base method, and then modifies the style information by changing the font used for the WebPart control being rendered.

protected override Style CreateWebPartChromeStyle(WebPart part, 
  PartChromeType chromeType)
{
  Style finalStyle = new Style();
  finalStyle.CopyFrom(base.CreateWebPartChromeStyle(part, chromeType));
  finalStyle.Font.Name = "Verdana";
  return finalStyle;
}
Protected Overrides Function CreateWebPartChromeStyle _
  (ByVal part As WebPart, ByVal chromeType As PartChromeType) As Style

  Dim finalStyle As New Style()
  finalStyle.CopyFrom(MyBase.CreateWebPartChromeStyle(Part, chromeType))
  finalStyle.Font.Name = "Verdana"
  Return finalStyle
End Function

If you load the Web page in a browser, you can see that the font used in the WebPart controls is the one specified in the overridden CreateWebPartChromeStyle method.

Remarks

The CreateWebPartChromeStyle method creates a Style object that is used by the WebPartChrome object to render a WebPart control. The default method creates style attributes based on the PartChromeType property value of the WebPart control referenced in the webPart parameter.

A special situation occurs when a WebPart control is selected. If the page is in a page display mode where controls can be selected, and the current control is actually selected, the default CreateWebPartChromeStyle method also merges the style information of the control with the style information from the SelectedPartChromeStyle property.

Notes to Inheritors

If you inherit from the WebPartChrome class, you can optionally override the CreateWebPartChromeStyle(WebPart, PartChromeType) method, and merge the style information from the base method with custom style attributes that you want to add. For a demonstration, see the code in the Example section.

Applies to

See also