TreeView.StateImageList 属性

定义

获取或设置图像列表,该列表用于指示 TreeView 及其节点的状态。

public:
 property System::Windows::Forms::ImageList ^ StateImageList { System::Windows::Forms::ImageList ^ get(); void set(System::Windows::Forms::ImageList ^ value); };
public System.Windows.Forms.ImageList StateImageList { get; set; }
public System.Windows.Forms.ImageList? StateImageList { get; set; }
member this.StateImageList : System.Windows.Forms.ImageList with get, set
Public Property StateImageList As ImageList

属性值

用于指示 ImageList 及其节点的状态的 TreeView

示例

下面的代码示例演示 了 StateImageList 属性。 若要运行此示例,请将代码粘贴到 Windows 窗体中,然后从窗体的构造函数或Load事件处理程序调用 InitializeCheckTreeView

    TreeView^ checkTreeView;
private:
    void InitializeCheckTreeView()
    {
        checkTreeView = gcnew TreeView();

        // Show check boxes for the TreeView. This
        // will cause the StateImageList to be used.
        checkTreeView->CheckBoxes = true;

        // Create the StateImageList and add two images.
        checkTreeView->StateImageList = gcnew ImageList();
        checkTreeView->StateImageList->Images->Add(SystemIcons::Question);
        checkTreeView->StateImageList->Images->Add(SystemIcons::Exclamation);

        // Add some nodes to the TreeView and the TreeView to the form.
        checkTreeView->Nodes->Add("Node1");
        checkTreeView->Nodes->Add("Node2");
        this->Controls->Add(checkTreeView);
    }
TreeView checkTreeView;
private void InitializeCheckTreeView()
{
    checkTreeView = new TreeView();
    
    // Show check boxes for the TreeView. This
    // will cause the StateImageList to be used.
    checkTreeView.CheckBoxes = true;

    // Create the StateImageList and add two images.
    checkTreeView.StateImageList = new ImageList();
    checkTreeView.StateImageList.Images.Add(SystemIcons.Question);
    checkTreeView.StateImageList.Images.Add(SystemIcons.Exclamation);
    
    // Add some nodes to the TreeView and the TreeView to the form.
    checkTreeView.Nodes.Add("Node1");
    checkTreeView.Nodes.Add("Node2");
    this.Controls.Add(checkTreeView);
}
Private checkTreeView As TreeView

Private Sub InitializeCheckTreeView() 
    checkTreeView = New TreeView()
    
    ' Show check boxes for the TreeView.
    checkTreeView.CheckBoxes = True
    
    ' Create the StateImageList and add two images.
    checkTreeView.StateImageList = New ImageList()
    checkTreeView.StateImageList.Images.Add(SystemIcons.Question)
    checkTreeView.StateImageList.Images.Add(SystemIcons.Exclamation)
    
    ' Add some nodes to the TreeView and the TreeView to the form.
    checkTreeView.Nodes.Add("Node1")
    checkTreeView.Nodes.Add("Node2")
    Me.Controls.Add(checkTreeView)

End Sub

注解

若要指示 的状态 TreeNode,请设置 StateImageList 属性,并为每个 设置 StateImageKeyStateImageIndex 属性 TreeNode

中显示 TreeView 的状态图像默认为 16 x 16 像素。 ImageSize设置 的 StateImageList 属性不会影响图像的显示方式。 但是,当app.config文件包含以下条目时,将根据系统 DPI 设置调整状态图像的大小:

<appSettings>  
  <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />  
</appSettings>  

CheckBoxes当 的 TreeView 属性设置为 trueStateImageList 属性设置为 时,中包含的TreeView每个TreeNode图像分别显示 中的StateImageList第一个和第二个图像,以指示未选中或已选中状态。 在将节点TreeView添加到 之前,应设置 StateImageList 属性,以防止在设计时为未设置状态映像的节点显示状态图像。

适用于