TreeViewEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 AfterCheck 控制項的 AfterCollapse、AfterExpand、AfterSelect 或 TreeView 事件資料。
public ref class TreeViewEventArgs : EventArgs
public class TreeViewEventArgs : EventArgs
type TreeViewEventArgs = class
inherit EventArgs
Public Class TreeViewEventArgs
Inherits EventArgs
- 繼承
範例
下列範例說明自訂 TreeView 的 。 藉由繼承 TreeView 類別,這個自訂版本具有一般 TreeView 的所有功能。 變更建構函式中的各種屬性值可提供獨特的外觀。 ShowPlusMinus因為 屬性設定為 false,所以自訂控制項也會覆寫 OnAfterSelect 方法,以便在按一下節點時展開和折迭。
透過這種方式自訂的控制項可以在整個組織中使用,讓您輕鬆地提供一致的介面,而不需要在每個個別專案中指定控制項屬性。
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
備註
如需處理事件的詳細資訊,請參閱 處理和引發事件。
建構函式
TreeViewEventArgs(TreeNode) |
初始化指定樹狀節點之 TreeViewEventArgs 類別的新執行個體。 |
TreeViewEventArgs(TreeNode, TreeViewAction) |
初始化指定樹狀節點和使用引發事件的動作型別來初始化 TreeViewEventArgs 類別的新執行個體。 |
屬性
Action |
取得引發事件的動作類型。 |
Node |
取得已核取、展開、收合或選取的樹狀節點。 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |