PartChromeState 枚举

定义

指定控件及其周围的边框是处于正常状态还是最小化状态。

public enum class PartChromeState
public enum PartChromeState
type PartChromeState = 
Public Enum PartChromeState
继承
PartChromeState

字段

Minimized 1

处于折叠或最小化状态的控件和边框。

Normal 0

处于正常状态的控件和边框。

示例

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

The first part of the example contains the code for the custom control, named TextDisplayWebPart. 由于控件派生自 WebPart,因此它还继承类提供的公共属性 Part ,包括使用该 ChromeState 枚举作为其返回类型的属性 PartChromeState

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 设置其 ChromeState 属性。 在浏览器中加载页面后,第二个控件实例将最小化。

<%@ 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>

注解

PartChromeState枚举表示Web 部件控件及其周围边框可以处于的可能可见状态。

适用于

另请参阅