HorizontalAlign 枚举

定义

指定容器中的项的水平对齐方式。

public enum class HorizontalAlign
[System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.HorizontalAlignConverter))]
public enum HorizontalAlign
[<System.ComponentModel.TypeConverter(typeof(System.Web.UI.WebControls.HorizontalAlignConverter))>]
type HorizontalAlign = 
Public Enum HorizontalAlign
继承
HorizontalAlign
属性

字段

Center 2

容器的内容居中。

Justify 4

容器的内容均匀展开,与左右边距对齐。

Left 1

容器的内容左对齐。

NotSet 0

未设置水平对齐方式。

Right 3

容器的内容右对齐。

示例

下面的示例演示设置 HorizontalAlign 控件的 Panel 属性如何更改控件所包含的Panel控件文本Label的水平对齐方式。

<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  protected void HorizontalAlignList_SelectedIndexChanged(object sender, EventArgs e)
  {
    switch (HorizontalAlignList.SelectedValue)
    {
      case "Left":
        Panel1.HorizontalAlign = HorizontalAlign.Left;
        break;
      case "Center":
        Panel1.HorizontalAlign = HorizontalAlign.Center;
        break;
      case "Justify":
        Panel1.HorizontalAlign = HorizontalAlign.Justify;
        break;
      default:
        Panel1.HorizontalAlign = HorizontalAlign.Right;
        break;
    }
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>HorizontalAlign Example</title> 
 </head>
 <body>
    <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.">
         </asp:Label>
       </asp:Panel>
 
       <br />
 
       <asp:Label ID="Label2" runat="server" Text="Horizontal Alignment:"></asp:Label>
       <asp:DropDownList ID="HorizontalAlignList" runat="server" AutoPostBack="True" 
         OnSelectedIndexChanged="HorizontalAlignList_SelectedIndexChanged">
         <asp:ListItem Selected="True">Left</asp:ListItem>
         <asp:ListItem>Center</asp:ListItem>
         <asp:ListItem>Right</asp:ListItem>
         <asp:ListItem>Justify</asp:ListItem>
       </asp:DropDownList>
 
    </form>
 </body>
 </html>
<%@ Page Language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  Protected Sub HorizontalAlignList_SelectedIndexChanged()
    
    Select Case HorizontalAlignList.SelectedValue
      Case "Left"
        Panel1.HorizontalAlign = HorizontalAlign.Left
      Case "Center"
        Panel1.HorizontalAlign = HorizontalAlign.Center
      Case "Justify"
        Panel1.HorizontalAlign = HorizontalAlign.Justify
      Case Else
        Panel1.HorizontalAlign = HorizontalAlign.Right
    End Select
    
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>HorizontalAlign Example</title> 
 </head>
 <body>
    <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.">
         </asp:Label>
       </asp:Panel>
 
       <br />
 
       <asp:Label ID="Label2" runat="server" Text="Horizontal Alignment:"></asp:Label>
       <asp:DropDownList ID="HorizontalAlignList" runat="server" AutoPostBack="True" 
         onselectedindexchanged="HorizontalAlignList_SelectedIndexChanged">
         <asp:ListItem Selected="True">Left</asp:ListItem>
         <asp:ListItem>Center</asp:ListItem>
         <asp:ListItem>Right</asp:ListItem>
         <asp:ListItem>Justify</asp:ListItem>
       </asp:DropDownList>
 
    </form>
 </body>
 </html>

注解

HorizontalAlign枚举表示容器中项的水平对齐选项,例如 TableCell

适用于