Panel.HorizontalAlign 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定在面板中內容的水平對齊。
public:
virtual property System::Web::UI::WebControls::HorizontalAlign HorizontalAlign { System::Web::UI::WebControls::HorizontalAlign get(); void set(System::Web::UI::WebControls::HorizontalAlign value); };
[System.ComponentModel.Bindable(true)]
public virtual System.Web.UI.WebControls.HorizontalAlign HorizontalAlign { get; set; }
public virtual System.Web.UI.WebControls.HorizontalAlign HorizontalAlign { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.HorizontalAlign : System.Web.UI.WebControls.HorizontalAlign with get, set
member this.HorizontalAlign : System.Web.UI.WebControls.HorizontalAlign with get, set
Public Overridable Property HorizontalAlign As HorizontalAlign
屬性值
其中一個 HorizontalAlign 值。 預設為 NotSet
。
- 屬性
例外狀況
水平對齊不是其中一個 HorizontalAlign 值。
範例
下列範例說明如何靠右對齊或靠左對齊 中的 Panel控件。
注意
下列程式代碼範例會使用單一檔案程式代碼模型,如果直接複製到程式代碼後置檔案,可能無法正常運作。 此程式代碼範例必須複製到具有.aspx擴展名的空白文本檔。 如需 Web Forms 程式代碼模型的詳細資訊,請參閱 ASP.NET Web Forms 頁面代碼模型。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!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" >
<head>
<title>Panel Example</title>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e) {
Label l = new Label();
l.Text = "This panel contains a label control.";
Panel1.Controls.Add(l);
}
void Button1_Click(Object sender, EventArgs e) {
if (Panel1.HorizontalAlign == HorizontalAlign.Left) {
Panel1.HorizontalAlign = HorizontalAlign.Right;
Button1.Text = "Left justify text within Panel";
}
else {
Panel1.HorizontalAlign = HorizontalAlign.Left;
Button1.Text = "Right justify text within Panel";
}
}
</script>
</head>
<body>
<h3>Panel Example</h3>
<form id="form1" runat="server">
<asp:Panel id="Panel1" Height="200" Width="100" BackColor="Gainsboro"
Wrap="True" HorizontalAlign="Right" runat="server"/>
<br />
<asp:Button id="Button1" OnClick="Button1_Click"
Text="Left justify text within panel" runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!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" >
<head>
<title>Panel Example</title>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim l As New Label()
l.Text = "This panel contains a label control."
Panel1.Controls.Add(l)
End Sub
Sub Button1_Click(sender As Object, e As EventArgs)
If Panel1.HorizontalAlign = HorizontalAlign.Left Then
Panel1.HorizontalAlign = HorizontalAlign.Right
Button1.Text = "Left justify text within Panel"
Else
Panel1.HorizontalAlign = HorizontalAlign.Left
Button1.Text = "Right justify text within Panel"
End If
End Sub
</script>
</head>
<body>
<h3>Panel Example</h3>
<form id="form1" runat="server">
<asp:Panel id="Panel1" Height="200" Width="100" BackColor="Gainsboro"
Wrap="True" HorizontalAlign="Right" runat="server"/>
<br />
<asp:Button id="Button1" OnClick="Button1_Click"
Text="Left justify text within panel" runat="server"/>
</form>
</body>
</html>
備註
使用這個屬性來指定 中 Panel專案的對齊方式。