Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
HorizontalAlign Enumeration
Collapse the table of content
Expand the table of content

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
© 2015 Microsoft