TreeViewEventArgs Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Fornece dados para o AfterCheck, AfterCollapse, AfterExpand, ou AfterSelect eventos de um TreeView controlo.
public ref class TreeViewEventArgs : EventArgs
public class TreeViewEventArgs : EventArgs
type TreeViewEventArgs = class
inherit EventArgs
Public Class TreeViewEventArgs
Inherits EventArgs
- Herança
Exemplos
O exemplo seguinte ilustra um .TreeView Ao herdar a TreeView classe, esta versão personalizada tem toda a funcionalidade de uma versão normal TreeView. Alterar vários valores de propriedades no construtor confere uma aparência única. Como a ShowPlusMinus propriedade está definida como falsa, o controlo personalizado também sobrepõe o OnAfterSelect método para que os nós possam ser expandidos e colapsados quando são clicados.
Um controlo personalizado desta forma pode ser utilizado em toda a organização, facilitando a disponibilização de uma interface consistente sem exigir que as propriedades de controlo sejam especificadas em cada projeto individual.
public ref class CustomizedTreeView: public TreeView
{
public:
CustomizedTreeView()
{
// Customize the TreeView control by setting various properties.
BackColor = System::Drawing::Color::CadetBlue;
FullRowSelect = true;
HotTracking = true;
Indent = 34;
ShowPlusMinus = false;
// The ShowLines property must be false for the FullRowSelect
// property to work.
ShowLines = false;
}
protected:
virtual void OnAfterSelect( TreeViewEventArgs^ e ) override
{
// Confirm that the user initiated the selection.
// This prevents the first node from expanding when it is
// automatically selected during the initialization of
// the TreeView control.
if ( e->Action != TreeViewAction::Unknown )
{
if ( e->Node->IsExpanded )
{
e->Node->Collapse();
}
else
{
e->Node->Expand();
}
}
// Remove the selection. This allows the same node to be
// clicked twice in succession to toggle the expansion state.
SelectedNode = nullptr;
}
};
public class CustomizedTreeView : TreeView
{
public CustomizedTreeView()
{
// Customize the TreeView control by setting various properties.
BackColor = System.Drawing.Color.CadetBlue;
FullRowSelect = true;
HotTracking = true;
Indent = 34;
ShowPlusMinus = false;
// The ShowLines property must be false for the FullRowSelect
// property to work.
ShowLines = false;
}
protected override void OnAfterSelect(TreeViewEventArgs e)
{
// Confirm that the user initiated the selection.
// This prevents the first node from expanding when it is
// automatically selected during the initialization of
// the TreeView control.
if (e.Action != TreeViewAction.Unknown)
{
if (e.Node.IsExpanded)
{
e.Node.Collapse();
}
else
{
e.Node.Expand();
}
}
// Remove the selection. This allows the same node to be
// clicked twice in succession to toggle the expansion state.
SelectedNode = null;
}
}
Public Class CustomizedTreeView
Inherits TreeView
Public Sub New()
' Customize the TreeView control by setting various properties.
BackColor = System.Drawing.Color.CadetBlue
FullRowSelect = True
HotTracking = True
Indent = 34
ShowPlusMinus = False
' The ShowLines property must be false for the FullRowSelect
' property to work.
ShowLines = False
End Sub
Protected Overrides Sub OnAfterSelect(ByVal e As TreeViewEventArgs)
' Confirm that the user initiated the selection.
' This prevents the first node from expanding when it is
' automatically selected during the initialization of
' the TreeView control.
If e.Action <> TreeViewAction.Unknown Then
If e.Node.IsExpanded Then
e.Node.Collapse()
Else
e.Node.Expand()
End If
End If
' Remove the selection. This allows the same node to be
' clicked twice in succession to toggle the expansion state.
SelectedNode = Nothing
End Sub
End Class
Observações
Para obter mais informações sobre como manipular eventos, consulte Manipulando e gerando eventos.
Construtores
| Name | Description |
|---|---|
| TreeViewEventArgs(TreeNode, TreeViewAction) |
Inicializa uma nova instância da TreeViewEventArgs classe para o nó de árvore especificado e com o tipo de ação especificado que gerou o evento. |
| TreeViewEventArgs(TreeNode) |
Inicializa uma nova instância da TreeViewEventArgs classe para o nó de árvore especificado. |
Propriedades
| Name | Description |
|---|---|
| Action |
Recebe o tipo de ação que elevou o evento. |
| Node |
Obtém o nó da árvore que foi verificado, expandido, colapsado ou selecionado. |
Métodos
| Name | Description |
|---|---|
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
| GetHashCode() |
Serve como função de hash predefinida. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do atual Object. (Herdado de Object) |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |