TreeView.StateImageList 属性

定义

获取或设置图像列表,该列表用于指示 TreeView 及其节点的状态。Gets or sets the image list that is used to indicate the state of the TreeView and its nodes.

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; }
member this.StateImageList : System.Windows.Forms.ImageList with get, set
Public Property StateImageList As ImageList

属性值

ImageList

用于指示 ImageList 及其节点的状态的 TreeViewThe ImageList used for indicating the state of the TreeView and its nodes.

示例

下面的代码示例演示了 StateImageList 属性。The following code example demonstrates the StateImageList property. 若要运行此示例,请将代码粘贴到 Windows 窗体中,并 InitializeCheckTreeView 从窗体的构造函数或 Load 事件处理程序调用。To run this example, paste the code into a Windows Form and call InitializeCheckTreeView from the form's constructor or Load event handler.

    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 属性,同时 StateImageKey StateImageIndex 为每个设置或属性 TreeNodeTo indicate the state of a TreeNode, set the StateImageList property and also set the StateImageKey or StateImageIndex property for each TreeNode.

默认情况下,中显示的状态图像 TreeView 是 16 x 16 像素。The state images displayed in the TreeView are 16 x 16 pixels by default. 设置 ImageSize 的属性 StateImageList 将不会影响图像的显示方式。Setting the ImageSize property of the StateImageList will have no effect on how the images are displayed. 但是,当 app.config 文件包含以下项时,将根据系统 DPI 设置调整状态图像的大小:However, the state images are resized according to the system DPI setting when the app.config file contains the following entry:

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

当的 CheckBoxes 属性 TreeView 设置为 true 且设置了属性时 StateImageList ,中包含的每个都将 TreeNode 显示中的 TreeView 第一个和第二个图像, StateImageList 分别指示未选中或选中状态。When the CheckBoxes property of a TreeView is set to true and the StateImageList property is set, each TreeNode that is contained in the TreeView displays the first and second images from the StateImageList to indicate an unchecked or checked state, respectively. 你应在 StateImageList 将节点添加到之前设置属性 TreeView ,以防止在设计时为未设置状态映像的节点显示状态图像。You should set the StateImageList property before you add nodes to the TreeView to prevent state images being shown at design time for nodes that do not have a state image set.

适用于