• C#(三十)之C#comboBox ListView treeView



    comboBox下拉列表框属性

    Items:下拉列表框选项

    DropDownStyle:控制组合框的外观和功能

    Simple:单一的样式

    DropDown:默认样式(可输入)

    DropDownList:与默认样式看着一样,但不可输入。

    ListView 列表视图属性

    Activeation:

    Standard:标准连续双击图标所发生的事件

    Oneclick:单机发生的事件

    Twoclick:不需要连续双击,两次单机即可

    Largeimagelist:存储大图标集合

    Smallimagelist:存储小图标集合

    View:显示样式

    Tile:平铺

    List:列表

    LargeIcon:大图标

    SmallIcon:小图标

    Details:详细

    Columns:详细信息视图中显示的列

    ListView 列表视图事件

    ItemActive:在激活某一项时发生。

    columnClick:在单击列标头时发生。

    treeView树状视图属性:

    nodes:控件中根节点

    imageindex:选中的图片

    selectimageindex:选中之后的图片

    SelectNode:选中节点

    如下图所示:

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-nORX28aQ-1656122785106)(https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/dadc087da6d34099ad4c4bc62d92406e~tplv-k3u1fbpfcp-zoom-1.image “1555492312851584.png”)]

    测试使用全部代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
     
    namespace _0416Day
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                int num = comboBox1.SelectedIndex;
                if( num == 0)
                {
                    label1.ForeColor = Color.LightPink;
                }
                else if(num == 1)
                {
                    label1.ForeColor = Color.BlueViolet;
                }
                else if(num == 2)
                {
                    label1.ForeColor = Color.Blue;
                }
                else if (num == 3)
                {
                    label1.ForeColor = Color.Coral;
                }
     
            }
     
            /**
             * 平铺按钮
             */
            private void button1_Click(object sender, EventArgs e)
            {
                listView.View = View.Tile;
            }
     
            /**
             * 列表按钮
             */
            private void button2_Click(object sender, EventArgs e)
            {
                listView.View = View.List;
            }
     
            /**
             * 大图标按钮
             */
            private void button3_Click(object sender, EventArgs e)
            {
                listView.View = View.LargeIcon;
            }
     
            /**
             * 小图标按钮
             */
            private void button4_Click(object sender, EventArgs e)
            {
                listView.View = View.SmallIcon;
            }
     
            /**
             * 详细按钮
             */
            private void button5_Click(object sender, EventArgs e)
            {
                listView.View = View.Details;
            }
     
            private void listView_ItemActivate(object sender, EventArgs e)
            {
                // 获取对应文档路径
                string mydoc = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                string mymusic = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
                switch(listView.SelectedIndices[0])
                {
                    case 0:System.Diagnostics.Process.Start("calc");break;
                    case 1: System.Diagnostics.Process.Start(mydoc); break;
                    case 2: System.Diagnostics.Process.Start("IExplore"); break;
                    case 3: System.Diagnostics.Process.Start(mymusic); break;
                    case 4: System.Diagnostics.Process.Start("notepad"); break;
                }
            }
     
            private void listView_ColumnClick(object sender, ColumnClickEventArgs e)
            {
                if (listView.Sorting == SortOrder.None)
                {
                    listView.Sorting = SortOrder.Ascending;
                }
                else if (listView.Sorting == SortOrder.Ascending)
                {
                    listView.Sorting = SortOrder.Descending;
                }
                else
                {
                    listView.Sorting = SortOrder.Ascending;
                }
            }
     
            private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
            {
                // 获取对应文档路径
                string mydoc = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                string mymusic = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
                switch (e.Node.Text)
                {
                    case "计算器": System.Diagnostics.Process.Start("calc"); break;
                    case "我的电脑": System.Diagnostics.Process.Start(mydoc); break;
                    case "我的IE": System.Diagnostics.Process.Start("IExplore"); break;
                    case "我的音乐": System.Diagnostics.Process.Start(mymusic); break;
                    case "我的笔记本": System.Diagnostics.Process.Start("notepad"); break;
                }
            }
     
            /**
             * 选中项目中添加节点
             */
            private void button7_Click(object sender, EventArgs e)
            {
                TreeNode cyaa = new TreeNode("cyaa");
                cyaa.ImageIndex = 0;
                cyaa.SelectedImageIndex = 0;
                treeView.SelectedNode.Nodes.Add(cyaa);
            }
     
            /**
             * 添加根节点和子节点
             */
            private void button6_Click(object sender, EventArgs e)
            {
                TreeNode cy1 = new TreeNode("cy1");
                cy1.ImageIndex = 0;
                cy1.SelectedImageIndex = 0;
                treeView.Nodes.Add(cy1);
     
                TreeNode cy1a = new TreeNode("cy1a");
                cy1a.ImageIndex = 1;
                cy1a.SelectedImageIndex = 1;
                cy1.Nodes.Add(cy1a);
     
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156

    有好的建议,请在下方输入你的评论。

    欢迎访问个人博客
    https://guanchao.site

    欢迎访问小程序:

    在这里插入图片描述

  • 相关阅读:
    推荐14个写Java代码的好习惯
    Springboot毕设项目程序员专属社交交友平台的设计于实现v1aeq(java+VUE+Mybatis+Maven+Mysql)
    七、Linux中一些符号的含义和宿主目录的介绍
    Gitlab部署管理
    vue 父组件给子组件传递一个函数,子组件调用父组件中的方法
    图论算法
    实现定时器的两种方法:使用windows api定时器 和使用c++11/14 定时器
    2-2线性表-链表
    桶排序的代码
    SLAM中提到的相机位姿到底指什么?
  • 原文地址:https://blog.csdn.net/qq_39708228/article/details/125455967