Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

PanelStyle Class

Note: This class is new in the .NET Framework version 2.0.

Represents the style for a Panel control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public class PanelStyle : Style
public class PanelStyle extends Style
public class PanelStyle extends Style

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.

You can specify an image to display in the background of the panel by setting the BackImageUrl property. The horizontal alignment of the contents of the panel is indicated by the HorizontalAlign property. The direction of controls that contain text within the panel control can be specified by setting the Direction property.

The following code example demonstrates creating a PanelStyle object and setting its properties. This example has two parts:

A partial class, PanelStylecs_aspx, that demonstrates creating a new PanelStyle object and setting its properties.

A Web Forms page that uses the PanelStylecs_aspx example as its code-behind file.

The first part of the example demonstrates creating a PanelStyle object, myPanelStyle, and setting its properties. Then 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); 
    }
}

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" >
  <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>

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Web.UI.WebControls.Style
        System.Web.UI.WebControls.PanelStyle
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.