PartChromeType 列舉

定義

指定圍繞 Web 組件控制項的框線類型。Specifies the kind of border that surrounds a Web Parts control.

public enum class PartChromeType
public enum PartChromeType
type PartChromeType = 
Public Enum PartChromeType
繼承
PartChromeType

欄位

BorderOnly 4

只有框線,無標題列。A border only, without a title bar.

Default 0

框線設定,其繼承自組件控制項的包含區域。A border setting inherited from the part control's containing zone.

None 2

無框線,也無標題列。No border and no title bar.

TitleAndBorder 1

標題列和框線。A title bar and a border.

TitleOnly 3

只有標提列,無框線。A title bar only, without a border.

範例

下列程式碼範例會使用 ASP.NET 網頁中參考PartChromeType的自訂WebPart控制項, 示範列舉型別的宣告式用法。The following code examples demonstrate the declarative use of the PartChromeType enumeration by using a custom WebPart control referenced in an ASP.NET Web page. 若要讓程式碼範例執行, 您必須編譯此原始程式碼。For the code example to run, you must compile this source code. 您可以明確地進行編譯, 並將產生的元件放在網站的 Bin 資料夾或全域組件快取中。You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. 或者, 您可以將原始程式碼放在您網站的 App_Code 資料夾中, 在執行時間會以動態方式編譯該程式碼。Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. 如需示範這兩種編譯方法的逐步解說, 請參閱逐步解說:開發和使用自訂 Web 服務器控制項For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Web Server Control.

範例的第一個部分包含自訂控制項的程式碼, 名稱為TextDisplayWebPartThe first part of the example contains the code for the custom control, named TextDisplayWebPart. 因為控制項衍生WebPart自, 所以它也會ChromeType繼承Part類別所提供的通用屬性, 包括屬性, 它會使用PartChromeType列舉做為其傳回型別。Because the control derives from WebPart, it also inherits the common properties that the Part class provides, including the ChromeType property, which uses the PartChromeType enumeration as its return type.

using System;
using System.Security.Permissions;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
  public class TextDisplayWebPart : WebPart
  {
    private String _contentText = null;
    TextBox input;
    Label DisplayContent;
    const string _subTitle = "Contoso, Ltd";

    public TextDisplayWebPart()
    {
      this.AllowClose = false;
    }

    [
      Personalizable(PersonalizationScope.User, true),
      WebBrowsable()
    ]
    public String ContentText
    {
      get { return _contentText; }
      set { _contentText = value; }
    }

    protected override void CreateChildControls()
    {
      Controls.Clear();
      DisplayContent = new Label();
      DisplayContent.BackColor = 
        System.Drawing.Color.LightBlue;
      DisplayContent.Text = this.ContentText;
      this.Controls.Add(DisplayContent);
      input = new TextBox();
      this.Controls.Add(input);
      Button update = new Button();
      update.Text = "Set Label Content";
      update.Click += new EventHandler(this.submit_Click);
      this.Controls.Add(update);
      ChildControlsCreated = true;
    }

    private void submit_Click(object sender, EventArgs e)
    {
      // Update the label string.
      if (!string.IsNullOrEmpty(input.Text))
      {
        this.ContentText = Page.Server.HtmlEncode(input.Text) + @"<br />";
        // Clear the input textbox.
        input.Text = String.Empty;
        DisplayContent.Text = this.ContentText;
      }
    }
  }
}
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls

<AspNetHostingPermission(SecurityAction.Demand, _
  Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
  Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class TextDisplayWebPart
    Inherits WebPart
    Private _contentText As String = Nothing
    Private input As TextBox
    Private DisplayContent As Label
    
    
    Public Sub New() 
      Me.AllowClose = False
    End Sub
    
    <Personalizable(), WebBrowsable()>  _
    Public Property ContentText() As String 
        Get
            Return _contentText
        End Get
        Set
            _contentText = value
        End Set
    End Property
     
    Protected Overrides Sub CreateChildControls() 
        Controls.Clear()
        DisplayContent = New Label()
        DisplayContent.Text = Me.ContentText
        DisplayContent.BackColor = _
          System.Drawing.Color.LightBlue
        Me.Controls.Add(DisplayContent)
        input = New TextBox()
        Me.Controls.Add(input)
        Dim update As New Button()
        update.Text = "Set Label Content"
        AddHandler update.Click, AddressOf Me.submit_Click
        Me.Controls.Add(update)
        ChildControlsCreated = True
    
    End Sub
    
    
    Private Sub submit_Click(ByVal sender As Object, _
                             ByVal e As EventArgs) 
        ' Update the label string.
        If input.Text <> String.Empty Then
            Me.ContentText = Page.Server.HtmlEncode(input.Text) + "<br />"
            ' Clear the input textbox.
            input.Text = String.Empty
            DisplayContent.Text = Me.ContentText
        End If
    
    End Sub
    
End Class

End Namespace

請注意, 在網頁的宣告式標記中, TextDisplayWebPart控制項的第二個實例會將其ChromeType屬性值設定為 titleonly.rdl。Note that in the declarative markup for the Web page, the second instance of the TextDisplayWebPart control sets its ChromeType property value to TitleOnly. 在瀏覽器中載入頁面之後, 第二個控制項實例會出現最小化。After you load the page in a browser, the second control instance appears minimized. 當您展開第二個控制項時, 它只會有沒有框線的標題列。When you expand the second control, it has only a title bar without a border.

<%@ page language="C#" %>
<%@ register tagprefix="aspSample" 
             Namespace="Samples.AspNet.CS.Controls" 
             Assembly="TextDisplayWebPartCS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server" />
    <asp:webpartzone
      id="WebPartZone1"
      runat="server"
      backcolor="#99cccc">
        <parttitlestyle font-bold="true" forecolor="#ffffff" />
        <partstyle
          borderwidth="1px" 
          borderstyle="Solid" 
          bordercolor="#81AAF2" />
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" 
            Description="A text content WebPart control."
            ChromeType="TitleAndBorder"
            width="350px" />
        </zonetemplate>
    </asp:webpartzone>
    <asp:webpartzone
      id="WebPartZone2"
      runat="server"
      backcolor="#99cccc">
        <parttitlestyle font-bold="true" forecolor="#ffffff" />
        <partstyle
          borderwidth="1px" 
          borderstyle="Solid" 
          bordercolor="#81AAF2" />
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart2" 
            title = "Text Content WebPart 2" 
            Description="A text content WebPart control."
            ChromeType="TitleOnly"
            ChromeState="Minimized"
            width="350px" />
        </zonetemplate>
    </asp:webpartzone>
  </form>
</body>
</html>
<%@ page language="VB" %>
<%@ register tagprefix="aspSample" 
             Namespace="Samples.AspNet.VB.Controls" 
             Assembly="TextDisplayWebPartVB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server" />
    <asp:webpartzone
      id="WebPartZone1"
      runat="server"
      backcolor="#99cccc">
        <parttitlestyle font-bold="true" forecolor="#ffffff" />
        <partstyle
          borderwidth="1px" 
          borderstyle="Solid" 
          bordercolor="#81AAF2" />
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" 
            Description="A text content WebPart control."
            ChromeType="TitleAndBorder"
            width="350px" />
        </zonetemplate>
    </asp:webpartzone>
    <asp:webpartzone
      id="WebPartZone2"
      runat="server"
      backcolor="#99cccc">
        <parttitlestyle font-bold="true" forecolor="#ffffff" />
        <partstyle
          borderwidth="1px" 
          borderstyle="Solid" 
          bordercolor="#81AAF2" />
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart2" 
            title = "Text Content WebPart 2" 
            Description="A text content WebPart control."
            ChromeType="TitleOnly"
            ChromeState="Minimized"
            width="350px" />
        </zonetemplate>
    </asp:webpartzone>
  </form>
</body>
</html>

備註

元件控制項的PartChromeType列舉會決定環繞 Web 組件控制項的框線類型。A part control's PartChromeType enumeration determines what kind of border surrounds a Web Parts control. 選項包括僅顯示標題列、僅限框線、標題列和框線, 或兩者皆非。Options include showing a title bar only, a border only, a title bar and border, or neither.

如果在元件控制項的ChromeType屬性上, 列舉值設定為 [預設], 控制項會從包含控制項之區域的PartChromeType屬性繼承其設定。If the enumeration value is set to Default on the ChromeType property of a part control, the control inherits its setting from the PartChromeType property of the zone that contains the control.

適用於

另請參閱