PanelStyle 類別

定義

代表 Panel 控制項的樣式。Represents the style for a Panel control.

public ref class PanelStyle : System::Web::UI::WebControls::Style
public class PanelStyle : System.Web.UI.WebControls.Style
type PanelStyle = class
    inherit Style
Public Class PanelStyle
Inherits Style
繼承

範例

下列程式碼範例示範如何建立PanelStyle物件並設定其屬性。The following code example demonstrates creating a PanelStyle object and setting its properties. 這個範例有兩個部分:This example has two parts:

部分類別, PanelStylecs_aspx示範如何建立新PanelStyle的物件並設定其屬性。A partial class, PanelStylecs_aspx, that demonstrates creating a new PanelStyle object and setting its properties.

使用PanelStylecs_aspx範例做為其程式碼後置檔案的 Web form 頁面。A Web Forms page that uses the PanelStylecs_aspx example as its code-behind file.

範例的第一個部分示範如何建立PanelStyle物件, myPanelStyle以及如何設定其屬性。The first part of the example demonstrates creating a PanelStyle object, myPanelStyle, and setting its properties. 然後會針對Panel1面板和Panel2面板呼叫myPanelStyle 方法,並同時套用至這兩個專案。ApplyStyleThen the ApplyStyle method is called for both the Panel1 panel and the Panel2 panel, and myPanelStyle is applied to both of them.

public partial class PanelStylecs_aspx : Page
{
    void Page_Load(object sender, EventArgs e)
    {
        StateBag panelState = new StateBag();
        PanelStyle myPanelStyle = new PanelStyle(panelState);
        
        // Set the properties of the PanelStyle class.
        myPanelStyle.HorizontalAlign = HorizontalAlign.Center;
        myPanelStyle.ScrollBars = ScrollBars.Both;
        myPanelStyle.Wrap = false;
        myPanelStyle.Direction = ContentDirection.LeftToRight;
        myPanelStyle.BackImageUrl = @"~\images\picture.jpg";

        // Use the ApplyStyle method of the Panel control to apply
        // the settings from the myPanelStyle object.
        Panel1.ApplyStyle(myPanelStyle);
        Panel2.ApplyStyle(myPanelStyle); 
    }
}
Partial Class PanelStylevb_aspx
    Inherits Page

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Dim panelState As StateBag = New StateBag()
        Dim myPanelStyle As PanelStyle = New PanelStyle(panelState)

        ' Set the properties of the PanelStyle class.
        myPanelStyle.HorizontalAlign = HorizontalAlign.Center
        myPanelStyle.ScrollBars = ScrollBars.Both
        myPanelStyle.Wrap = False
        myPanelStyle.Direction = ContentDirection.LeftToRight
        myPanelStyle.BackImageUrl = "~\images\picture.jpg"

        ' Use the ApplyStyle method of the Panel control to apply
        ' the settings from the myPanelStyle object.
        Panel1.ApplyStyle(myPanelStyle)
        Panel2.ApplyStyle(myPanelStyle)
        
    End Sub

End Class

範例的第二個部分顯示 .aspx 檔案, 該檔案與先前的範例搭配使用。The second part of the example shows an .aspx file that is used with the previous example.

<%@ Page Language="C#" CodeFile="PanelStyle.cs" Inherits="PanelStylecs_aspx" %>

<!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 runat="server">
    <title>PanelStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <h3>PanelStyle Example</h3>
      <asp:Panel id="Panel1" 
        runat="server" 
        width="150" 
        height="50">
        This is the Panel1 panel control.
      </asp:Panel>
      <br /><br />
      <asp:Panel id="Panel2" 
        runat="server" 
        width="150" 
        height="50">
        This is the Panel2 panel control.
      </asp:Panel>
    </form>
  </body>
</html>
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="PanelStyle.vb" Inherits="PanelStylevb_aspx" %>

<!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 runat="server">
    <title>PanelStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <h3>PanelStyle Example</h3>
      <asp:Panel id="Panel1" 
        runat="server" 
        width="150" 
        height="50">
        This is the Panel1 panel control.
      </asp:Panel>
      <br /><br />
      <asp:Panel id="Panel2" 
        runat="server" 
        width="150" 
        height="50">
        This is the Panel2 panel control.
      </asp:Panel>
    </form>
  </body>
</html>

備註

PanelStyle類別是用來表示面板控制項的樣式設定。The PanelStyle class is used to represent the style settings for a panel control. 它會封裝控制台外觀的屬性, 並可套用至多個面板控制項, 以提供常見的外觀。It encapsulates the properties that control the appearance of a panel and can be applied to multiple panel controls to provide a common appearance.

您可以藉由設定BackImageUrl屬性來指定要在面板背景中顯示的影像。You can specify an image to display in the background of the panel by setting the BackImageUrl property. 面板內容的水準對齊方式是由HorizontalAlign屬性所表示。The horizontal alignment of the contents of the panel is indicated by the HorizontalAlign property. 您可以藉由設定Direction屬性來指定面板控制項中包含文字的控制項的方向。The direction of controls that contain text within the panel control can be specified by setting the Direction property.

建構函式

PanelStyle(StateBag)

初始化 PanelStyle 類別的新執行個體。Initializes a new instance of the PanelStyle class.

屬性

BackColor

取得或設定 Web 伺服器控制項的背景色彩。Gets or sets the background color of the Web server control.

(繼承來源 Style)
BackImageUrl

取得或設定面板控制項背景影像的 URL。Gets or sets the URL of the background image for the panel control.

BorderColor

取得或設定 Web 伺服器控制項的框線色彩。Gets or sets the border color of the Web server control.

(繼承來源 Style)
BorderStyle

取得或設定 Web 伺服器控制項的框線樣式。Gets or sets the border style of the Web server control.

(繼承來源 Style)
BorderWidth

取得或設定 Web 伺服器控制項的框線寬度。Gets or sets the border width of the Web server control.

(繼承來源 Style)
CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(繼承來源 Component)
Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(繼承來源 Component)
CssClass

取得或設定用戶端上 Web 伺服器控制項所呈現的階層式樣式表 (CSS)。Gets or sets the cascading style sheet (CSS) class rendered by the Web server control on the client.

(繼承來源 Style)
DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(繼承來源 Component)
Direction

取得或設定在面板控制項中包含文字的控制項之顯示方向。Gets or sets the direction in which to display controls that include text in a panel control.

Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(繼承來源 Component)
Font

取得與 Web 伺服器控制項關聯的字型屬性。Gets the font properties associated with the Web server control.

(繼承來源 Style)
ForeColor

取得或設定 Web 伺服器控制項的前景色彩 (通常是文字的色彩)。Gets or sets the foreground color (typically the color of the text) of the Web server control.

(繼承來源 Style)
Height

取得或設定 Web 伺服器控制項的高度。Gets or sets the height of the Web server control.

(繼承來源 Style)
HorizontalAlign

取得或設定在面板控制項中內容的水平對齊。Gets or sets the horizontal alignment of the contents within a panel control.

IsEmpty

保護的 (Protected) 屬性。A protected property. 取得值,指出狀態包中是否已定義任何樣式項目。Gets a value indicating whether any style elements have been defined in the state bag.

(繼承來源 Style)
IsTrackingViewState

傳回值,指出是否任何的樣式項目都已經在狀態包中定義。Returns a value indicating whether any style elements have been defined in the state bag.

(繼承來源 Style)
RegisteredCssClass

取得使用控制項註冊的階層式樣式表 (CSS) 類別。Gets the cascading style sheet (CSS) class that is registered with the control.

(繼承來源 Style)
ScrollBars

取得或設定在面板控制項中捲軸的可視性和位置。Gets or sets the visibility and position of scroll bars in a panel control.

Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(繼承來源 Component)
ViewState

取得保存樣式項目的狀態包。Gets the state bag that holds the style elements.

(繼承來源 Style)
Width

取得或設定 Web 伺服器控制項的寬度。Gets or sets the width of the Web server control.

(繼承來源 Style)
Wrap

取得或設定值,指示面板中的內容是否換行。Gets or sets a value indicating whether the content wraps within the panel.

方法

AddAttributesToRender(HtmlTextWriter)

將需要呈現的 HTML 屬性和樣式加入至指定的 HtmlTextWriter 中。Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter. 這個方法主要由控制項開發人員使用。This method is primarily used by control developers.

(繼承來源 Style)
AddAttributesToRender(HtmlTextWriter, WebControl)

將需要呈現的 HTML 屬性和樣式加入至指定的 HtmlTextWriter 和 Web 伺服器控制項中。Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter and Web server control. 這個方法主要由控制項開發人員使用。This method is primarily used by control developers.

(繼承來源 Style)
CopyFrom(Style)

Style 類別目前的執行個體,複製指定的 PanelStyle 物件的樣式屬性。Duplicates the style properties of the specified Style object for the current instance of the PanelStyle class.

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。Releases all resources used by the Component.

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(繼承來源 Component)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
FillStyleAttributes(CssStyleCollection, IUrlResolutionService)

將指定物件的樣式屬性加入 CssStyleCollection 物件中。Adds the specified object's style properties to a CssStyleCollection object.

(繼承來源 Style)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(繼承來源 Component)
GetStyleAttributes(IUrlResolutionService)

擷取指定 CssStyleCollection 實作物件的 IUrlResolutionService 物件。Retrieves the CssStyleCollection object for the specified IUrlResolutionService-implemented object.

(繼承來源 Style)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
LoadViewState(Object)

載入先前儲存的狀態。Loads the previously saved state.

(繼承來源 Style)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
MergeWith(Style)

將指定 Style 物件的樣式設定與 PanelStyle 類別目前的執行個體結合。Combines the style settings of the specified Style object with the current instance of the PanelStyle class.

Reset()

PanelStyle 類別移除任何已定義的樣式設定。Removes any defined style settings from the PanelStyle class.

SaveViewState()

保護的 (Protected) 方法。A protected method. 儲存叫用 TrackViewState() 方法之後,任何已變更的狀態。Saves any state that has been modified after the TrackViewState() method was invoked.

(繼承來源 Style)
SetBit(Int32)

保護的內部方法。A protected internal method. 設定內部位元遮罩欄位,表示儲存在狀態包中的樣式屬性。Sets an internal bitmask field that indicates the style properties that are stored in the state bag.

(繼承來源 Style)
SetDirty()

標記 Style,以便將其狀態記錄在檢視狀態中。Marks the Style so that its state will be recorded in view state.

(繼承來源 Style)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Style)
TrackViewState()

保護的 (Protected) 方法。A protected method. 在控制項上標記追蹤狀態變更的開頭。Marks the beginning for tracking state changes on the control. 任何在追蹤開始後的變更都會被追蹤,並儲存成控制項檢視狀態的一部分。Any changes made after tracking has begun will be tracked and saved as part of the control view state.

(繼承來源 Style)

事件

Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(繼承來源 Component)

明確介面實作

IStateManager.IsTrackingViewState

取得值,指出伺服器控制項是否正在追蹤其檢視狀態變更。Gets a value that indicates whether a server control is tracking its view state changes.

(繼承來源 Style)
IStateManager.LoadViewState(Object)

載入先前儲存的狀態。Loads the previously saved state.

(繼承來源 Style)
IStateManager.SaveViewState()

傳回包含狀態變更的物件。Returns the object containing state changes.

(繼承來源 Style)
IStateManager.TrackViewState()

啟動追蹤狀態的變更。Starts tracking state changes.

(繼承來源 Style)

適用於

另請參閱