Export (0) Print
Expand All
Expand Minimize

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
CenterThe contents of a container are centered.
JustifyThe contents of a container are uniformly spread out and aligned with both the left and right margins.
LeftThe contents of a container are left justified.
NotSetThe horizontal alignment is not set.
RightThe contents of a container are right justified.

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="http://www.w3.org/1999/xhtml" >
    <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.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft