Panel.ScrollBars 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定在 Panel 控制項中捲軸的可視性和位置。
public:
virtual property System::Web::UI::WebControls::ScrollBars ScrollBars { System::Web::UI::WebControls::ScrollBars get(); void set(System::Web::UI::WebControls::ScrollBars value); };
public virtual System.Web.UI.WebControls.ScrollBars ScrollBars { get; set; }
member this.ScrollBars : System.Web.UI.WebControls.ScrollBars with get, set
Public Overridable Property ScrollBars As ScrollBars
屬性值
其中一個 ScrollBars 列舉值。 預設為 None
。
範例
下列程式代碼範例示範如何以宣告方式將 屬性設定 ScrollBars 為 Auto
。 面板包含數據表,其整個內容超過面板的大小。 這會導致在轉譯面板時自動顯示垂直和水平滾動條。 然後,使用者可以捲動以檢視數據表中的所有數據。
注意
下列程式代碼範例會使用單一檔案程式代碼模型,如果直接複製到程式代碼後置檔案,可能無法正常運作。 此程式代碼範例必須複製到擴展名為 .aspx的空文本檔。 如需 Web Forms 程式代碼模型的詳細資訊,請參閱 ASP.NET 網頁代碼模型。
<%@ 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">
private void Page_Load(object sender, EventArgs e)
{
// Add more rows and columns to the table than can
// be displayed in the panel area.
// Scroll bars will be required to view all the data.
// Add rows and columns to the table.
for (int rowNum = 0; rowNum < 51; rowNum++)
{
TableRow tempRow = new TableRow();
for (int cellNum = 0; cellNum < 11; cellNum++)
{
TableCell tempCell = new TableCell();
tempCell.Text =
String.Format("({0}, {1})", rowNum, cellNum);
tempRow.Cells.Add(tempCell);
}
Table1.Rows.Add(tempRow);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
<title>Panel Scrollbars - C# Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Panel.ScrollBars Property Example</h3>
<asp:Panel ID="Panel1" runat="Server"
Height="300px" Width="400px"
BackColor="Aqua" ScrollBars="Auto">
<asp:Table ID="Table1" runat="Server"></asp:Table>
</asp:Panel>
</div>
</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">
Private Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs)
' Add more rows and columns to the table than can
' be displayed in the panel area.
' Scroll bars will be required to view all the data.
' Add rows and columns to the table.
Dim rowNum As Integer
For rowNum = 0 To 50
Dim tempRow As New TableRow
Dim cellNum As Integer
For cellNum = 0 To 10
Dim tempCell As New TableCell
tempCell.Text = _
String.Format("({0}, {1})", rowNum, cellNum)
tempRow.Cells.Add(tempCell)
Next
Table1.Rows.Add(tempRow)
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
<title>Panel Scrollbars - VB.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Panel.ScrollBars Property Example</h3>
<asp:Panel ID="Panel1" runat="Server"
Height="300px" Width="400px"
BackColor="Aqua" ScrollBars="Auto">
<asp:Table ID="Table1" runat="Server"></asp:Table>
</asp:Panel>
</div>
</form>
</body>
</html>
下列程式代碼範例示範如何以程式設計方式設定 ScrollBars 屬性。 ListBox控件會填ScrollBars入列舉值。 面板中顯示的滾動條會根據使用者從清單框選取的值而變更。
注意
下列程式代碼範例會使用單一檔案程式代碼模型,如果直接複製到程式代碼後置檔案,可能無法正常運作。 此程式代碼範例必須複製到擴展名為 .aspx的空文本檔。 如需 Web Forms 程式代碼模型的詳細資訊,請參閱 ASP.NET 網頁代碼模型。
<%@ 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">
private void Page_Load(object sender, EventArgs e)
{
// Add more rows and columns to the table than can
// be displayed in the panel area.
// Scroll bars will be required to view all the data.
// Add rows and columns to the table.
for (int rowNum = 0; rowNum < 51; rowNum++)
{
TableRow tempRow = new TableRow();
for (int cellNum = 0; cellNum < 11; cellNum++)
{
TableCell tempCell = new TableCell();
tempCell.Text =
String.Format("({0}, {1})", rowNum, cellNum);
tempRow.Cells.Add(tempCell);
}
Table1.Rows.Add(tempRow);
}
}
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// Determine which list item was clicked.
// Display the selected scroll bars in the panel.
switch (ListBox1.SelectedIndex)
{
case 0:
Panel1.ScrollBars = ScrollBars.None;
break;
case 1:
Panel1.ScrollBars = ScrollBars.Horizontal;
break;
case 2:
Panel1.ScrollBars = ScrollBars.Vertical;
break;
case 3:
Panel1.ScrollBars = ScrollBars.Both;
break;
case 4:
Panel1.ScrollBars = ScrollBars.Auto;
break;
default:
throw new Exception("Select a valid list item.");
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Panel.ScrollBars Property Example</h3>
<h4>Select the scrollbars to display in the panel.</h4>
<asp:ListBox ID="ListBox1" runat="Server"
Rows="5" AutoPostBack="True"
SelectionMode="Single"
OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
<asp:ListItem>None</asp:ListItem>
<asp:ListItem>Horizontal</asp:ListItem>
<asp:ListItem>Vertical</asp:ListItem>
<asp:ListItem>Both</asp:ListItem>
<asp:ListItem>Auto</asp:ListItem>
</asp:ListBox>
<hr />
<asp:Panel ID="Panel1" runat="Server"
Height="300px" Width="400px" BackColor="Aqua">
<asp:Table ID="Table1" runat="Server" />
</asp:Panel>
</div>
</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">
Private Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs)
' Add more rows and columns to the table than can
' be displayed in the panel area.
' Scroll bars will be required to view all the data.
' Add rows and columns to the table.
Dim i As Integer
For i = 0 To 50
Dim tempRow As New TableRow
Dim j As Integer
For j = 0 To 10
Dim tempCell As New TableCell
tempCell.Text = "(" & i & "," & j & ")"
tempRow.Cells.Add(tempCell)
Next j
Table1.Rows.Add(tempRow)
Next i
End Sub
Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As EventArgs)
' Determine which list item was clicked.
' Display the selected scroll bars in the panel.
Select Case (ListBox1.SelectedIndex)
Case 0
Panel1.ScrollBars = ScrollBars.None
Case 1
Panel1.ScrollBars = ScrollBars.Horizontal
Case 2
Panel1.ScrollBars = ScrollBars.Vertical
Case 3
Panel1.ScrollBars = ScrollBars.Both
Case 4
Panel1.ScrollBars = ScrollBars.Auto
Case Else
Throw New Exception("Select a valid list item.")
End Select
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Panel.ScrollBars Property Example</h3>
<h4>Select the scrollbars to display in the panel.</h4>
<asp:ListBox ID="ListBox1" runat="Server"
Rows="5" AutoPostBack="True" SelectionMode="Single"
OnSelectedIndexChanged="ListBox1_SelectedIndexChanged">
<asp:ListItem>None</asp:ListItem>
<asp:ListItem>Horizontal</asp:ListItem>
<asp:ListItem>Vertical</asp:ListItem>
<asp:ListItem>Both</asp:ListItem>
<asp:ListItem>Auto</asp:ListItem>
</asp:ListBox>
<hr />
<asp:Panel ID="Panel1" runat="Server"
Height="300px" Width="400px" BackColor="Aqua">
<asp:Table ID="Table1" runat="Server" />
</asp:Panel>
</div>
</form>
</body>
</html>
備註
ScrollBars使用屬性可指定控件中Panel滾動條的可見性和位置。 此屬性是使用其中 ScrollBars 一個列舉值來設定。 下表列出可能的值。
值 | 描述 |
---|---|
None |
不顯示捲軸。 |
Horizontal |
只會顯示水平滾動條。 |
Vertical |
只會顯示垂直滾動條。 |
Both |
同時顯示水平和垂直捲軸。 |
Auto |
如有必要,會顯示水準、垂直或兩個滾動條。 否則不顯示捲軸。 |
如果您為 屬性指定Auto
,當控件中Panel的內容大小超過控件本身的大小Panel時,會自動顯示滾動ScrollBars條。 例如,如果 Panel 控件包含數據表,而且面板不夠寬,無法顯示數據表中的所有數據列,則會顯示垂直滾動條。 如果數據表的大小超過面板的高度和寬度,則會同時顯示垂直和水準滾動條。
注意
只有支援 HTML 4.0 或更新版本的瀏覽器才支援此屬性。