TreeViewEventArgs.Node プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


カスタマイズされた 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からTreeViewEventArgs.Node プロパティを検索する場合は、下記のリンクをクリックしてください。

- TreeViewEventArgs.Node プロパティのページへのリンク