Panel.Direction 屬性

定義

取得或設定包含文字之控制項在 Panel 控制項中的顯示方向。

public:
 virtual property System::Web::UI::WebControls::ContentDirection Direction { System::Web::UI::WebControls::ContentDirection get(); void set(System::Web::UI::WebControls::ContentDirection value); };
public virtual System.Web.UI.WebControls.ContentDirection Direction { get; set; }
member this.Direction : System.Web.UI.WebControls.ContentDirection with get, set
Public Overridable Property Direction As ContentDirection

屬性值

其中一個 ContentDirection 列舉值。 預設為 NotSet

範例

下列程式碼範例示範如何以程式設計方式設定 Direction 屬性。 ListBox控制項會填 ContentDirection 入列舉值。 面板中標籤和選項按鈕的顯示方向會根據使用者從清單方塊中選取的值而變更。 請注意,此範例使用英文文字。 因此,選取值時 RightToLeft ,文字會對齊控制項右側 Panel ,但會維護英文文字的左至右順序。 在真實世界中,如果您顯示由左至右語言的文字, Direction 則不會將 屬性 RightToLeft 設定為 。

注意

下列程式碼範例會使用單一檔案程式碼模型,如果直接複製到程式碼後置檔案,可能無法正常運作。 此程式碼範例必須複製到副檔名為 .aspx 的空白文字檔中。 如需Web Form程式碼模型的詳細資訊,請參閱ASP.NET Web Forms頁碼模型

<%@ Page Language="VB" %>

<!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.Direction Property Example</title>
<script runat="server">
          
        Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

            ' Determine which list item was clicked.
            ' Change the display direction of content in the panel.
            Select Case (ListBox1.SelectedIndex)
                Case 0
                    Panel1.Direction = ContentDirection.NotSet
                Case 1
                    Panel1.Direction = ContentDirection.LeftToRight
                Case 2
                    Panel1.Direction = ContentDirection.RightToLeft
                Case Else
                    Throw New Exception("You did not select a valid list item.")
            End Select

        End Sub
     
    </script>
</head>
<body>
    <form id="Form1" runat="server">
        
        <h3>Panel.Direction Property Example</h3>
        
        <h4>Select the content display direction for the 
        controls in the panel.</h4>
        
        <asp:ListBox ID="ListBox1"
            Rows="3"
            AutoPostBack="True"
            SelectionMode="Single"
            OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"
            runat="server">
                <asp:ListItem>NotSet</asp:ListItem>
            <asp:ListItem>LeftToRight</asp:ListItem> 
            <asp:ListItem>RightToLeft</asp:ListItem>                               
        </asp:ListBox>
            
        <hr />              
        
        <asp:Panel ID="Panel1"
            Height="100px"
            Width="300px"
            BackColor="Aqua"           
            runat="server">            
            
            <asp:Label ID="Label1"
                Text = "Select a programming language"
                runat="server">              
            </asp:Label><br /><br />
            
            <asp:RadioButton id="Radio1"
                Text="C#" 
                Checked="False" 
                GroupName="RadioGroup1" 
                runat="server">
            </asp:RadioButton><br />

            <asp:RadioButton id="Radio2"
                Text="Visual Basic" 
                Checked="False" 
                GroupName="RadioGroup1" 
                runat="server">
            </asp:RadioButton><br />
                   
            <asp:RadioButton id="Radio3"
                Text="C++" 
                Checked="False" 
                GroupName="RadioGroup1" 
                runat="server">
            </asp:RadioButton><br />           
            
        </asp:Panel>           
         
    </form>
</body>
</html>

備註

Direction使用 屬性可指定控制項的顯示方向,這些控制項包含控制項中的 Panel 文字。 此屬性是使用其中 ContentDirection 一個列舉值來設定。 下表列出可能的值。

描述
NotSet 未設定內容方向。
LeftToRight 內容方向由左至右。
RightToLeft 內容方向由右至左。

如果您指定 LeftToRight ,則包含從左至右顯示文字的子控制項。 如果您指定 RightToLeft ,則包含由右至左顯示文字的子控制項。 用來 RightToLeft 顯示從右至左撰寫之語言的文字,例如阿拉伯文或希伯來文。

注意

只有支援 HTML 4.0 或更新版本的瀏覽器才支援此屬性。

適用於

另請參閱