TreeNodeStyle.CopyFrom(Style) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定 Style 物件的樣式屬性複製到目前物件 TreeNodeStyle 中。
public:
override void CopyFrom(System::Web::UI::WebControls::Style ^ s);
public override void CopyFrom(System.Web.UI.WebControls.Style s);
override this.CopyFrom : System.Web.UI.WebControls.Style -> unit
Public Overrides Sub CopyFrom (s As Style)
參數
範例
以下程式碼範例示範如何使用此 CopyFrom 方法將指定 Style 物件的樣式屬性複製到 TreeNodeStyle 呼叫該方法的物件中。 注意每個風格的物件都會被替換。
<%@ 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">
void Button_Click(Object sender, EventArgs e)
{
// Copy the leaf node styles from the TreeNodeOne TreeView into the
// TreeViewResults TreeView.
TreeViewResults.LeafNodeStyle.CopyFrom(TreeViewOne.LeafNodeStyle);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeStyle CopyFrom Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeStyle CopyFrom Example</h3>
<table cellspacing="30">
<tr>
<th>
TreeView One
</th>
<th>
TreeView Result
</th>
</tr>
<tr valign="top">
<td>
<!-- Set the styles for the leaf nodes declaratively. -->
<asp:TreeView id="TreeViewOne"
ExpandDepth="4"
LeafNodeStyle-BackColor="Yellow"
LeafNodeStyle-Font-Bold="true"
LeafNodeStyle-ForeColor="Black"
runat="server">
<Nodes>
<asp:TreeNode Text="Table of Contents"
SelectAction="None">
<asp:TreeNode Text="Chapter One">
<asp:TreeNode Text="Section 1.0">
<asp:TreeNode Text="Topic 1.0.1"/>
<asp:TreeNode Text="Topic 1.0.2"/>
<asp:TreeNode Text="Topic 1.0.3"/>
</asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</td>
<td>
<!-- Set the styles for the leaf nodes declaratively. -->
<asp:TreeView id="TreeViewResults"
ExpandDepth="4"
runat="server">
<Nodes>
<asp:TreeNode Text="Table of Contents"
SelectAction="None">
<asp:TreeNode Text="Chapter One">
<asp:TreeNode Text="Section 1.0">
<asp:TreeNode Text="Topic 1.0.1"/>
<asp:TreeNode Text="Topic 1.0.2"/>
<asp:TreeNode Text="Topic 1.0.3"/>
</asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</td>
</tr>
<tr>
<td>
<asp:Button ID="CopyNodeStyleButton"
Text="Copy LeafNodeStyle"
OnClick="Button_Click"
runat="server"/>
</td>
<td>
</td>
</tr>
</table>
</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">
Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
' Copy the leaf node styles from the TreeNodeOne TreeView into the
' TreeViewResults TreeView.
TreeViewResults.LeafNodeStyle.CopyFrom(TreeViewOne.LeafNodeStyle)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeStyle CopyFrom Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeStyle CopyFrom Example</h3>
<table cellspacing="30">
<tr>
<th>
TreeView One
</th>
<th>
TreeView Result
</th>
</tr>
<tr valign="top">
<td>
<!-- Set the styles for the leaf nodes declaratively. -->
<asp:TreeView id="TreeViewOne"
ExpandDepth="4"
LeafNodeStyle-BackColor="Yellow"
LeafNodeStyle-Font-Bold="true"
LeafNodeStyle-ForeColor="Black"
runat="server">
<Nodes>
<asp:TreeNode Text="Table of Contents"
SelectAction="None">
<asp:TreeNode Text="Chapter One">
<asp:TreeNode Text="Section 1.0">
<asp:TreeNode Text="Topic 1.0.1"/>
<asp:TreeNode Text="Topic 1.0.2"/>
<asp:TreeNode Text="Topic 1.0.3"/>
</asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</td>
<td>
<!-- Set the styles for the leaf nodes declaratively. -->
<asp:TreeView id="TreeViewResults"
ExpandDepth="4"
runat="server">
<Nodes>
<asp:TreeNode Text="Table of Contents"
SelectAction="None">
<asp:TreeNode Text="Chapter One">
<asp:TreeNode Text="Section 1.0">
<asp:TreeNode Text="Topic 1.0.1"/>
<asp:TreeNode Text="Topic 1.0.2"/>
<asp:TreeNode Text="Topic 1.0.3"/>
</asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</td>
</tr>
<tr>
<td>
<asp:Button ID="CopyNodeStyleButton"
Text="Copy LeafNodeStyle"
OnClick="Button_Click"
runat="server"/>
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
備註
使用該CopyFrom方法複製指定Style物件的樣式屬性,並呼叫此方法的物件。TreeNodeStyle
Note
目前物件中 TreeNodeStyle 的所有屬性都會被指定 Style 物件中相應的屬性所取代。
若要複製風格屬性而不替換已設定的值,請使用該 MergeWith 方法。