TreeNodeStyle Classe
Definição
public ref class TreeNodeStyle sealed : System::Web::UI::WebControls::Style
public sealed class TreeNodeStyle : System.Web.UI.WebControls.Style
type TreeNodeStyle = class
inherit Style
Public NotInheritable Class TreeNodeStyle
Inherits Style
- Herança
Exemplos
O exemplo de código a seguir demonstra como controlar a aparência dos nós pai no TreeView controle definindo as propriedades de estilo do TreeNodeStyle objeto que é retornado da ParentNodeStyle propriedade.The following code example demonstrates how to control the appearance of the parent nodes in the TreeView control by setting the style properties of the TreeNodeStyle object that is returned from the ParentNodeStyle property.
<%@ 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 HorizontalPadding_Changed(Object sender, EventArgs e)
{
// Programmatically set the HorizontalPadding property based on the
// user's selection.
ItemsTreeView.ParentNodeStyle.HorizontalPadding = Convert.ToInt32(HorizontalPaddingList.SelectedItem.Text);
}
void VerticalPadding_Changed(Object sender, EventArgs e)
{
// Programmatically set the VerticalPadding property based on the
// user's selection.
ItemsTreeView.ParentNodeStyle.VerticalPadding = Convert.ToInt32(VerticalPaddingList.SelectedItem.Text);
}
void NodeSpacing_Changed(Object sender, EventArgs e)
{
// Programmatically set the NodeSpacing property based on the
// user's selection.
ItemsTreeView.ParentNodeStyle.NodeSpacing = Convert.ToInt32(NodeSpacingList.SelectedItem.Text);
}
void ChildNodePadding_Changed(Object sender, EventArgs e)
{
// Programmatically set the ChildNodesPadding property based on the
// user's selection.
ItemsTreeView.ParentNodeStyle.ChildNodesPadding = Convert.ToInt32(ChildNodesPaddingList.SelectedItem.Text);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeStyle Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeStyle Example</h3>
<!-- Set the styles for the leaf nodes declaratively. -->
<asp:TreeView id="ItemsTreeView"
Font-Names= "Arial"
ForeColor="Blue"
ParentNodeStyle-ForeColor="Green"
ParentNodeStyle-HorizontalPadding="5"
ParentNodeStyle-VerticalPadding="5"
ParentNodeStyle-NodeSpacing="5"
ParentNodeStyle-ChildNodesPadding="5"
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 Text="Section 1.1">
<asp:TreeNode Text="Topic 1.1.1"/>
<asp:TreeNode Text="Topic 1.1.2"/>
<asp:TreeNode Text="Topic 1.1.3"/>
<asp:TreeNode Text="Topic 1.1.4"/>
</asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
<hr />
<h5>Select the style settings for the parent nodes.</h5>
<table cellpadding="5">
<tr align="right">
<td>
Horizontal Padding:
<asp:DropDownList id="HorizontalPaddingList"
AutoPostBack="true"
OnSelectedIndexChanged="HorizontalPadding_Changed"
runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem Selected="true">5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</td>
<td>
Vertical Padding:
<asp:DropDownList id="VerticalPaddingList"
AutoPostBack="true"
OnSelectedIndexChanged="VerticalPadding_Changed"
runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem Selected="true">5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr align="right">
<td>
Node Spacing:
<asp:DropDownList id="NodeSpacingList"
AutoPostBack="true"
OnSelectedIndexChanged="NodeSpacing_Changed"
runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem Selected="true">5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</td>
<td>
Child Nodes Padding:
<asp:DropDownList id="ChildNodesPaddingList"
AutoPostBack="true"
OnSelectedIndexChanged="ChildNodePadding_Changed"
runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem Selected="true">5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</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 HorizontalPadding_Changed(ByVal sender As Object, ByVal e As EventArgs)
' Programmatically set the HorizontalPadding property based on the
' user's selection.
ItemsTreeView.ParentNodeStyle.HorizontalPadding = Convert.ToInt32(HorizontalPaddingList.SelectedItem.Text)
End Sub
Sub VerticalPadding_Changed(ByVal sender As Object, ByVal e As EventArgs)
' Programmatically set the VerticalPadding property based on the
' user's selection.
ItemsTreeView.ParentNodeStyle.VerticalPadding = Convert.ToInt32(VerticalPaddingList.SelectedItem.Text)
End Sub
Sub NodeSpacing_Changed(ByVal sender As Object, ByVal e As EventArgs)
' Programmatically set the NodeSpacing property based on the
' user's selection.
ItemsTreeView.ParentNodeStyle.NodeSpacing = Convert.ToInt32(NodeSpacingList.SelectedItem.Text)
End Sub
Sub ChildNodePadding_Changed(ByVal sender As Object, ByVal e As EventArgs)
' Programmatically set the ChildNodesPadding property based on the
' user's selection.
ItemsTreeView.ParentNodeStyle.ChildNodesPadding = Convert.ToInt32(ChildNodesPaddingList.SelectedItem.Text)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeStyle Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeStyle Example</h3>
<!-- Set the styles for the leaf nodes declaratively. -->
<asp:TreeView id="ItemsTreeView"
Font-Names= "Arial"
ForeColor="Blue"
ParentNodeStyle-ForeColor="Green"
ParentNodeStyle-HorizontalPadding="5"
ParentNodeStyle-VerticalPadding="5"
ParentNodeStyle-NodeSpacing="5"
ParentNodeStyle-ChildNodesPadding="5"
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 Text="Section 1.1">
<asp:TreeNode Text="Topic 1.1.1"/>
<asp:TreeNode Text="Topic 1.1.2"/>
<asp:TreeNode Text="Topic 1.1.3"/>
<asp:TreeNode Text="Topic 1.1.4"/>
</asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
<hr />
<h5>Select the style settings for the parent nodes.</h5>
<table cellpadding="5">
<tr align="right">
<td>
Horizontal Padding:
<asp:DropDownList id="HorizontalPaddingList"
AutoPostBack="true"
OnSelectedIndexChanged="HorizontalPadding_Changed"
runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem Selected="true">5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</td>
<td>
Vertical Padding:
<asp:DropDownList id="VerticalPaddingList"
AutoPostBack="true"
OnSelectedIndexChanged="VerticalPadding_Changed"
runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem Selected="true">5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr align="right">
<td>
Node Spacing:
<asp:DropDownList id="NodeSpacingList"
AutoPostBack="true"
OnSelectedIndexChanged="NodeSpacing_Changed"
runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem Selected="true">5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</td>
<td>
Child Nodes Padding:
<asp:DropDownList id="ChildNodesPaddingList"
AutoPostBack="true"
OnSelectedIndexChanged="ChildNodePadding_Changed"
runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem Selected="true">5</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</form>
</body>
</html>
Comentários
Use a TreeNodeStyle classe para representar o estilo de um nó no TreeView controle.Use the TreeNodeStyle class to represent the style of a node in the TreeView control. O TreeView controle permite que você especifique características de estilo diferentes (como tamanho e cor da fonte) para cada um dos diferentes tipos de nó.The TreeView control allows you to specify different style characteristics (such as font size and color) for each of the different node types.
A tabela a seguir lista os estilos de nó que são suportados pela TreeNodeStyle classe.The following table lists the node styles that are supported by the TreeNodeStyle class.
| Propriedade de estilo do nóNode style property | DescriçãoDescription |
|---|---|
| HoverNodeStyle | As configurações de estilo para um nó quando o ponteiro do mouse está posicionado sobre ele.The style settings for a node when the mouse pointer is positioned over it. |
| LeafNodeStyle | As configurações de estilo dos nós folha.The style settings for the leaf nodes. |
| NodeStyle | As configurações de estilo padrão para um nó.The default style settings for a node. |
| ParentNodeStyle | As configurações de estilo para os nós pai.The style settings for the parent nodes. |
| RootNodeStyle | As configurações de estilo do nó raiz.The style settings for the root node. |
| SelectedNodeStyle | As configurações de estilo de um nó selecionado.The style settings for a selected node. |
Quando você define as propriedades de estilo do nó do TreeView controle, elas são aplicadas na seguinte ordem:When you set the node style properties of the TreeView control, they are applied in the following order:
RootNodeStyle, ParentNodeStyle ou LeafNodeStyle , dependendo do tipo de nó.RootNodeStyle, ParentNodeStyle, or LeafNodeStyle, depending on the node type.
A TreeNodeStyle classe herda a maioria de seus membros da Style classe.The TreeNodeStyle class inherits most of its members from the Style class. Ele estende a Style classe fornecendo propriedades que controlam a quantidade de espaço em volta do texto em um nó, bem como o espaço entre os nós adjacentes.It extends the Style class by providing properties that control the amount of space around the text in a node, as well as the space between adjacent nodes. Use a HorizontalPadding propriedade para controlar a quantidade de espaço à esquerda e à direita do texto em um nó.Use the HorizontalPadding property to control the amount of space to the left and right of the text in a node. Da mesma forma, a VerticalPadding propriedade controla a quantidade de espaço acima e abaixo do texto em um nó.Similarly, the VerticalPadding property controls the amount of space above and below the text in a node. Você pode controlar a quantidade de espaçamento entre o nó ao qual o TreeNodeStyle é aplicado e seus nós adjacentes definindo a NodeSpacing propriedade.You can control the amount of spacing between the node that the TreeNodeStyle is applied to and its adjacent nodes by setting the NodeSpacing property. Para controlar a quantidade de espaçamento entre um nó pai e um nó filho, use a ChildNodesPadding propriedade.To control the amount of spacing between a parent node and a child node, use the ChildNodesPadding property.
Para obter mais informações sobre as configurações de estilo herdadas, consulte Style .For more information about the inherited style settings, see Style.
Construtores
| TreeNodeStyle() |
Inicializa uma nova instância da classe TreeNodeStyle.Initializes a new instance of the TreeNodeStyle class. |
| TreeNodeStyle(StateBag) |
Inicializa uma nova instância da classe TreeNodeStyle com as informações do objeto StateBag especificado.Initializes a new instance of the TreeNodeStyle class with the specified StateBag object information. |
Propriedades
| BackColor |
Obtém ou define a cor da tela de fundo do controle do servidor Web.Gets or sets the background color of the Web server control. (Herdado de Style) |
| BorderColor |
Obtém ou define a cor de borda do controle de servidor Web.Gets or sets the border color of the Web server control. (Herdado de Style) |
| BorderStyle |
Obtém ou define o estilo de borda do controle de servidor Web.Gets or sets the border style of the Web server control. (Herdado de Style) |
| BorderWidth |
Obtém ou define a largura da borda do controle de servidor Web.Gets or sets the border width of the Web server control. (Herdado de Style) |
| CanRaiseEvents |
Obtém um valor que indica se o componente pode acionar um evento.Gets a value indicating whether the component can raise an event. (Herdado de Component) |
| ChildNodesPadding |
Obtém ou define a quantidade de espaço entre um nó pai e um nó filho para o qual o TreeNodeStyle classe é aplicada.Gets or sets the amount of space between a parent node and a child node to which the TreeNodeStyle class is applied. |
| Container |
Obtém o IContainer que contém o Component.Gets the IContainer that contains the Component. (Herdado de Component) |
| CssClass |
Obtém ou define a classe CSS (folha de estilos em cascata) renderizada pelo controle do servidor Web no cliente.Gets or sets the cascading style sheet (CSS) class rendered by the Web server control on the client. (Herdado de Style) |
| DesignMode |
Obtém um valor que indica se o Component está no modo de design no momento.Gets a value that indicates whether the Component is currently in design mode. (Herdado de Component) |
| Events |
Obtém a lista de manipuladores de eventos que estão anexados a este Component.Gets the list of event handlers that are attached to this Component. (Herdado de Component) |
| Font |
Obtém as propriedades de fonte associadas ao controle do servidor Web.Gets the font properties associated with the Web server control. (Herdado de Style) |
| ForeColor |
Obtém ou define a cor de primeiro plano (normalmente a cor do texto) do controle de servidor Web.Gets or sets the foreground color (typically the color of the text) of the Web server control. (Herdado de Style) |
| Height |
Obtém ou define a altura do controle do servidor Web.Gets or sets the height of the Web server control. (Herdado de Style) |
| HorizontalPadding |
Obtém ou define a quantidade de espaço à esquerda e à direita do texto no nó.Gets or sets the amount of space to the left and right of the text in the node. |
| ImageUrl |
Obtém ou define a URL para uma imagem exibida ao lado do nó.Gets or sets the URL to an image that is displayed next to the node. |
| IsEmpty |
Uma propriedade protegida.A protected property. Obtém um valor que indica se algum elemento de estilo foi definido no recipiente de estados.Gets a value indicating whether any style elements have been defined in the state bag. (Herdado de Style) |
| IsTrackingViewState |
Retorna um valor que indica se algum elemento de estilo foi definido no recipiente de estados.Returns a value indicating whether any style elements have been defined in the state bag. (Herdado de Style) |
| NodeSpacing |
Obtém ou define a quantidade de espaçamento vertical entre o nó ao qual o objeto TreeNodeStyle será aplicado e seus nós adjacentes.Gets or sets the amount of vertical spacing between the node to which the TreeNodeStyle object is applied and its adjacent nodes. |
| RegisteredCssClass |
Obtém a classe CSS (folha de estilos em cascata) que está registrada com o controle.Gets the cascading style sheet (CSS) class that is registered with the control. (Herdado de Style) |
| Site |
Obtém ou define o ISite do Component.Gets or sets the ISite of the Component. (Herdado de Component) |
| VerticalPadding |
Obtém ou define a quantidade de espaço acima e abaixo do texto de um nó.Gets or sets the amount of space above and below the text for a node. |
| ViewState |
Obtém o recipiente de estados que contém os elementos de estilo.Gets the state bag that holds the style elements. (Herdado de Style) |
| Width |
Obtém ou define a largura do controle de servidor Web.Gets or sets the width of the Web server control. (Herdado de Style) |
Métodos
| AddAttributesToRender(HtmlTextWriter) |
Adiciona atributos HTML e estilos que precisam ser renderizadas ao HtmlTextWriter especificado.Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter. Esse método é usado principalmente por desenvolvedores de controles.This method is primarily used by control developers. (Herdado de Style) |
| AddAttributesToRender(HtmlTextWriter, WebControl) |
Adiciona atributos HTML e estilos que precisam ser renderizados ao controle de servidor Web HtmlTextWriter especificado.Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter and Web server control. Esse método é usado principalmente por desenvolvedores de controles.This method is primarily used by control developers. (Herdado de Style) |
| CopyFrom(Style) |
Copia as propriedades de estilo do Style objeto atual TreeNodeStyle objeto.Copies the style properties of the specified Style object into the current TreeNodeStyle object. |
| CreateObjRef(Type) |
Cria um objeto que contém todas as informações relevantes necessárias para gerar um proxy usado para se comunicar com um objeto remoto.Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Herdado de MarshalByRefObject) |
| Dispose() |
Libera todos os recursos usados pelo Component.Releases all resources used by the Component. (Herdado de Component) |
| Dispose(Boolean) |
Libera os recursos não gerenciados usados pelo Component e opcionalmente libera os recursos gerenciados.Releases the unmanaged resources used by the Component and optionally releases the managed resources. (Herdado de Component) |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| FillStyleAttributes(CssStyleCollection, IUrlResolutionService) |
Adiciona as propriedades de estilo do objeto especificado a um objeto CssStyleCollection.Adds the specified object's style properties to a CssStyleCollection object. (Herdado de Style) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetLifetimeService() |
Obsoleto.
Recupera o objeto de serviço de tempo de vida atual que controla a política de ciclo de vida para esta instância.Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Herdado de MarshalByRefObject) |
| GetService(Type) |
Retorna um objeto que representa um serviço fornecido pelo Component ou pelo seu Container.Returns an object that represents a service provided by the Component or by its Container. (Herdado de Component) |
| GetStyleAttributes(IUrlResolutionService) |
Recupera o objeto CssStyleCollection especificado objeto implementado por IUrlResolutionService.Retrieves the CssStyleCollection object for the specified IUrlResolutionService-implemented object. (Herdado de Style) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| InitializeLifetimeService() |
Obsoleto.
Obtém um objeto de serviço de tempo de vida para controlar a política de tempo de vida para essa instância.Obtains a lifetime service object to control the lifetime policy for this instance. (Herdado de MarshalByRefObject) |
| LoadViewState(Object) |
Carrega o estado salvo anteriormente.Loads the previously saved state. (Herdado de Style) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| MemberwiseClone(Boolean) |
Cria uma cópia superficial do objeto MarshalByRefObject atual.Creates a shallow copy of the current MarshalByRefObject object. (Herdado de MarshalByRefObject) |
| MergeWith(Style) |
Combina as propriedades de estilo do Style objeto com as propriedades de estilo do atual TreeNodeStyle objeto.Combines the style properties of the specified Style object with the style properties of the current TreeNodeStyle object. |
| Reset() |
Retorna o TreeNodeStyle objeto ao seu estado original.Returns the TreeNodeStyle object to its original state. |
| SaveViewState() |
Um método protegido.A protected method. Salva qualquer estado que tenha sido modificado depois que o método TrackViewState() foi invocado.Saves any state that has been modified after the TrackViewState() method was invoked. (Herdado de Style) |
| SetBit(Int32) |
Um método interno protegido.A protected internal method. Define um campo interno de máscara de bits que indica as propriedades de estilo que estão armazenadas no recipiente de estados.Sets an internal bitmask field that indicates the style properties that are stored in the state bag. (Herdado de Style) |
| SetDirty() |
Marca o Style de maneira que seu estado seja registrado na exibição de estado.Marks the Style so that its state will be recorded in view state. (Herdado de Style) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Style) |
| TrackViewState() |
Um método protegido.A protected method. Marca o início para controlar alterações de estado no controle.Marks the beginning for tracking state changes on the control. Todas as alterações feitas após o início do acompanhamento serão acompanhadas e salvas como parte do estado de exibição do controle.Any changes made after tracking has begun will be tracked and saved as part of the control view state. (Herdado de Style) |
Eventos
| Disposed |
Ocorre quando o componente é disposto por uma chamada ao método Dispose().Occurs when the component is disposed by a call to the Dispose() method. (Herdado de Component) |
Implantações explícitas de interface
| IStateManager.IsTrackingViewState |
Obtém um valor que indica se um controle de servidor está acompanhando as alterações de estado de exibição.Gets a value that indicates whether a server control is tracking its view state changes. (Herdado de Style) |
| IStateManager.LoadViewState(Object) |
Carrega o estado salvo anteriormente.Loads the previously saved state. (Herdado de Style) |
| IStateManager.SaveViewState() |
Retorna o objeto que contém as alterações de estado.Returns the object containing state changes. (Herdado de Style) |
| IStateManager.TrackViewState() |
Inicia o controle de alterações de estado.Starts tracking state changes. (Herdado de Style) |