当前位置:网站首页>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
欢迎访问小程序:
边栏推荐
- Yyds dry inventory what is test driven development
- BUAA magpie nesting
- Containerization Foundation
- Multi project programming minimalist use case
- [Qt5] QT QWidget immediately appears and disappears
- Mysqldump data backup
- Princeton University, Peking University & UIUC | offline reinforcement learning with realizability and single strategy concentration
- [optimization model] Monte Carlo method of optimization calculation
- On Data Mining
- An article will give you a comprehensive understanding of the internal and external components of "computer"
猜你喜欢
[meisai] meisai thesis reference template
深入刨析的指针(题解)
遥感图像超分辨重建综述
[analysis of variance] single factor analysis and multi factor analysis
多项目编程极简用例
Research on cooperative control of industrial robots
Pytorch load data
RT thread -- FTP of LwIP (2)
1.16 - 校验码
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
随机推荐
MySQL 中的数据类型介绍
Pointer written test questions ~ approaching Dachang
SAP ALV cell level set color
[American competition] mathematical terms
2.2 STM32 GPIO operation
MPLS experiment
Introduction to DeNO
[slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board
2. GPIO related operations
Getting started with applet cloud development - getting user search content
Leetcode problem solving -- 108 Convert an ordered array into a binary search tree
施努卡:什么是视觉定位系统 视觉系统如何定位
Suggestions for new engineer team members
[risc-v] external interrupt
Mysqldump data backup
Image super resolution using deep revolutionary networks (srcnn) interpretation and Implementation
2、GPIO相关操作
3.2 detailed explanation of rtthread serial port device (V2)
Shell 传递参数
How do we make money in agriculture, rural areas and farmers? 100% for reference