TreeViewEventArgs.Action 속성
이벤트를 발생시킨 작업 형식을 가져옵니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문
‘선언
Public ReadOnly Property Action As TreeViewAction
‘사용 방법
Dim instance As TreeViewEventArgs
Dim value As TreeViewAction
value = instance.Action
public TreeViewAction Action { get; }
public:
property TreeViewAction Action {
TreeViewAction get ();
}
/** @property */
public TreeViewAction get_Action ()
public function get Action () : TreeViewAction
속성 값
이벤트를 발생시킨 TreeViewAction
예제
다음 예제에서는 사용자 지정된 TreeView를 보여 줍니다. 이 사용자 지정 버전은 TreeView 클래스를 상속함으로써 일반적인 TreeView의 모든 기능을 포함합니다. 생성자의 다양한 속성 값을 변경하여 고유한 모양을 만들 수 있습니다. ShowPlusMinus 속성이 false로 설정되어 있으므로 이 사용자 지정된 컨트롤은 노드를 클릭할 때 노드가 확장되거나 축소될 수 있도록 OnAfterSelect 메서드도 재정의합니다.
이 방법으로 사용자 지정된 컨트롤을 조직 전체에서 사용하면 각각의 개별 프로젝트에서 컨트롤 속성을 지정하지 않고도 일관된 인터페이스를 쉽게 제공할 수 있습니다.
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 'New
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 'OnAfterSelect
End Class 'CustomizedTreeView
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 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 extends TreeView
{
public CustomizedTreeView()
{
// Customize the TreeView control by setting various properties.
set_BackColor(System.Drawing.Color.get_CadetBlue());
set_FullRowSelect(true);
set_HotTracking(true);
set_Indent(34);
set_ShowPlusMinus(false);
// The ShowLines property must be false for the FullRowSelect
// property to work.
set_ShowLines(false);
} //CustomizedTreeView
protected 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.get_Action().Equals(TreeViewAction.Unknown))) {
if (e.get_Node().get_IsExpanded()) {
e.get_Node().Collapse();
}
else {
e.get_Node().Expand();
}
}
// Remove the selection. This allows the same node to be
// clicked twice in succession to toggle the expansion state.
set_SelectedNode(null);
} //OnAfterSelect
}//CustomizedTreeView
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원
참고 항목
참조
TreeViewEventArgs 클래스
TreeViewEventArgs 멤버
System.Windows.Forms 네임스페이스
TreeViewAction 열거형