当前位置:网站首页>C#(三十)之C#comboBox ListView treeView
C#(三十)之C#comboBox ListView treeView
2022-07-06 03:39:00 【camellias_】
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);
}
}
}
有好的建议,请在下方输入你的评论。
欢迎访问个人博客
https://guanchao.site
欢迎访问小程序:

边栏推荐
猜你喜欢

Svg drag point crop image JS effect

LTE CSFB test analysis

Image super-resolution using deep convolutional networks(SRCNN)解读与实现

施努卡:3d视觉检测应用行业 机器视觉3d检测

遥感图像超分辨率论文推荐

2.1 rtthread pin设备详解

1.16 - 校验码

How do we make money in agriculture, rural areas and farmers? 100% for reference

【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板

Precautions for single chip microcomputer anti reverse connection circuit
随机推荐
Pytorch基础——(1)张量(tensor)的初始化
The real machine cannot access the shooting range of the virtual machine, and the real machine cannot Ping the virtual machine
【Qt5】Qt QWidget立刻出现并消失
On Data Mining
User perceived monitoring experience
记录一下逆向任务管理器的过程
Precautions for single chip microcomputer anti reverse connection circuit
出现Permission denied的解决办法(750权限谨慎使用)
RT-Thread--Lwip之FTP(2)
[matlab] - draw a five-star red flag
A brief introduction to symbols and link libraries in C language
Schnuka: 3D vision detection application industry machine vision 3D detection
UDP reliable transport protocol (quic)
[practice] mathematics in lottery
Restful style
Map sorts according to the key value (ascending plus descending)
User experience index system
C language circular statement
2. GPIO related operations
Quartz misfire missed and compensated execution