PartChromeType 枚举

定义

指定围绕 Web 部件控件的边框的类型。

C#
public enum PartChromeType
继承
PartChromeType

字段

名称 说明
BorderOnly 4

只有边框,没有标题栏。

Default 0

从部件控件所在的区域继承的边框设置。

None 2

没有边框和标题栏。

TitleAndBorder 1

同时具有标题栏和边框。

TitleOnly 3

只有标题栏,没有边框。

示例

下面的代码示例演示如何使用 ASP.NET 网页中引用的 PartChromeType 自定义 WebPart 控件以声明方式使用 枚举。 若要运行代码示例,必须编译此源代码。 可以显式编译它,并将生成的程序集放入网站的 Bin 文件夹或全局程序集缓存中。 或者,可以将源代码放在站点的“App_Code”文件夹中,并在运行时对其进行动态编译。 有关演示这两种编译方法的演练,请参阅 演练:开发和使用自定义 Web 服务器控件

该示例的第一部分包含自定义控件的代码,名为 TextDisplayWebPart。 由于 控件派生自 WebPart,因此它还继承类提供的公共属性 Part ,包括 ChromeType 属性,该属性使用 PartChromeType 枚举作为其返回类型。

C#
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;
      }
    }
  }
}

请注意,在网页的声明性标记中,控件的第二个 TextDisplayWebPart 实例将其 ChromeType 属性值设置为 TitleOnly。 在浏览器中加载页面后,第二个控件实例显示为最小化。 展开第二个控件时,它只有一个没有边框的标题栏。

ASP.NET (C#)
<%@ 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>

注解

部件控件的 PartChromeType 枚举确定 Web 部件控件周围的边框类型。 选项包括仅显示标题栏、仅显示边框、标题栏和边框,或者两者都不显示。

如果枚举值在部件控件的 属性上 ChromeType 设置为 Default,则控件将从 PartChromeType 包含该控件的区域的 属性继承其设置。

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另请参阅