This documentation is archived and is not being maintained.

HorizontalAlign Enumeration

Specifies the horizontal alignment of items within a container.

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

public enum HorizontalAlign

Member nameDescription
NotSetThe horizontal alignment is not set.
LeftThe contents of a container are left justified.
CenterThe contents of a container are centered.
RightThe contents of a container are right justified.
JustifyThe contents of a container are uniformly spread out and aligned with both the left and right margins.

The HorizontalAlign enumeration represents the horizontal alignment options for items within a container, such as a TableCell.

The following example shows how setting the HorizontalAlign property of a Panel control changes the horizontal alignment for the text of a Label control that is contained by the Panel control.

<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<script runat="server">

  protected void HorizontalAlignList_SelectedIndexChanged(object sender, EventArgs e)
    switch (HorizontalAlignList.SelectedValue)
      case "Left":
        Panel1.HorizontalAlign = HorizontalAlign.Left;
      case "Center":
        Panel1.HorizontalAlign = HorizontalAlign.Center;
      case "Justify":
        Panel1.HorizontalAlign = HorizontalAlign.Justify;
        Panel1.HorizontalAlign = HorizontalAlign.Right;

<html xmlns="" >
    <title>HorizontalAlign Example</title> 
    <h3>HorizontalAlign Example</h3>
    <form id="form1" runat="server">

       <asp:Panel id="Panel1" Height="100" Width="200" BackColor="Gainsboro"
            Wrap="True" HorizontalAlign="Left" runat="server">
         <asp:Label ID="Label1" runat="server" Text="This panel contains a Label control.">

       <br />

       <asp:Label ID="Label2" runat="server" Text="Horizontal Alignment:"></asp:Label>
       <asp:DropDownList ID="HorizontalAlignList" runat="server" AutoPostBack="True" 
         <asp:ListItem Selected="True">Left</asp:ListItem>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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