最新文章 (全部类别)
VS2022消除编译警告
“SymmetricAlgorithm.Create(string)”已过时:“Cryptographic factory methods accepting an algorithm name are obsolete. Use the parameterless Create factory method on the algorithm type instead
SHA256Managed/SHA512Managed已过时:Derived cryptographic types are obsolete. Use the Create method on the base type instead
MD5CryptoServiceProvider已过时:Derived cryptographic types are obsolete. Use the Create method on the base type instead
C#使用HttpClient获取IP地址位置和网络信息
判断IP是否是外网IP、内网IP
C#使用HttpClient获取公网IP
WebRequest.Create(string)已过时:WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead
C#根据第三方提供的IP查询服务获取公网外网IP地址
html/dom/js/javascript开发记录
调试ASP.NETCore Web站点 - 清理IISExpress缓存数据(js,css)
EFCore+Oracle根据不同的Schema连接数据库
主程序集成CSFramework.EF 数据库框架(.NET7版本)
CSFramework.EF数据库框架简介(.NET8+EFCore)
迁移ECS服务器:导致ORACLE监听服务启动不了解决方案
SQLite数据库
VS2022编译报错:Visual Studio 容器工具需要 Docker Desktop
.NET 9 预览版+C#13新功能
EFCore禁用实体跟踪
WebApi开发框架V3.0 (.NETCore+EFCore) 增加AppSettings全局参数类
C#获取应用程序所有依赖的程序集
LINQ Expression 多条件复合条件组合(And/Or)
CSFrameworkV6客户案例 - MHR - 宁德时代制造人力资源系统
CS软件授权注册系统V3 - 发布证书
C/S软件授权注册系统V3.0(Winform+WebApi+.NET8+EFCore版本)
CS软件授权注册系统V3 - 购买方式
CS软件授权注册系统V3 - 试用版下载
CS软件授权注册系统-客户登记(制作证书)
C/S软件授权注册系统V3.0 - 管理员工具
CSFrameworkV6旗舰版开发框架 - 集成软件授权认证系统
CSFramework.Authentication 软件证书管理系统 - 制作软件客户授权证书
CSFramework.Authentication 软件证书管理系统 - MAC地址管理
CSFramework.Authentication 软件授权证书管理系统
Login/Logout接口调用dalUser的Login/Logout方法
C# Newtonsoft.Json.Linq.JObject 转对象
CSFramework.Authentication 软件授权认证系统 - 软件测试报告
C/S架构软件开发平台 - 旗舰版V6.0 - 底层框架迭代开发
C/S架构软件开发平台 - 旗舰版V6.1新功能 - 增加软件授权认证模块
C/S架构软件开发平台 - 旗舰版CSFrameworkV6 Bug修改记录
CS软件授权注册系统V3 - 开发手册 - 软件集成与用户注册
CS软件授权注册系统-模拟MES/ERP用户注册软件
CS软件授权注册系统-发布/部署WebApi服务器(IIS+.NET8+ASP.NETCore)
CS软件授权注册系统-VS2022调试WebApi接口
.NETCore Console控制台程序使用ILogger日志
CS软件授权注册系统-WebApi服务器介绍
ASP.NETCore集成Swagger添加Authorize按钮Bearer授权
CS软件授权注册系统-WebApi服务器配置
.NETCore WebApi发布到IIS服务器无法打开swagger
.NET8/ .NETCore /ASP.NETCore 部署WebApi到IIS服务器需要安装的运行环境
HTTP Error 500.31 - Failed to load ASP.NET Core runtime,Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.
.net敏捷开发,创造卓越

C# Mini版本文件浏览器.TreeView/ListView应用


C# Mini版本文件浏览器.TreeView/ListView应用C# Mini版文件浏览器.介绍TreeView及ListView应用

贴图图片

程序内用到System.Management.ManagementObjectCollection

ManagementObjectCollection类说明:
   
    //    Summary:
    //
    //     Represents different collections of management objects retrieved through
    //     WMI. The objects in this collection are of System.Management.ManagementBaseObject-derived
    //     types, including System.Management.ManagementObject and System.Management.ManagementClass.
    //     The collection can be the result of a WMI query executed through a System.Management.
    //     ManagementObjectSearcher,
    //     or an enumeration of management objects of a specified type retrieved through
    //     a System.Management.ManagementClass representing that type. In addition,
    //     this can be a collection of management objects related in a specified way
    //     to a specific management object - in this case the collection would be retrieved
    //     through a method such as System.Management.ManagementObject.GetRelated().
    //     The collection can be walked using the System.Management.ManagementObjectCollection.
    //     ManagementObjectEnumerator
    //     and objects in it can be inspected or manipulated for various management
    //     tasks.


顺便学学英文,总有好处。

下面是窗体源代码,多看看,别下载了源程序运行通过就不管事了。学程序要多看多写多总结---学三多

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.Globalization;
using System.IO;

namespace MiniExplorer
{
   
   //用TreeView实现文件浏览器
   public partial class frmMiniExplorer : Form
   {
      private const int Removable = 2;
      private const int LocalDisk = 3;
      private const int Network = 4;
      private const int CD = 5;
      
      public frmMiniExplorer()
      {
         InitializeComponent();
      }
      
      private void frmMiniExplorer_Load(object sender, EventArgs e)
      {
         LoadDrives();
         LoadListView();
      }
      
      //加载物理磁盘驱动器
      private void LoadDrives()
      {
         TreeNode nodeTemp = null;
         int imageIndex = 0;
         int selectIndex = 0;
         
         this.Cursor = Cursors.WaitCursor;
         
         tvFolders.Nodes.Clear();
         nodeTemp = new TreeNode("My Computer", 0, 0);
         tvFolders.Nodes.Add(nodeTemp);//加载根目录
         
         TreeNodeCollection nodeCollection = nodeTemp.Nodes;
         
         //用System.Management对象获取驱动器列表
         ManagementObjectCollection queryCollection = GetDriveList();
         
         foreach (ManagementObject mo in queryCollection)
         {
            switch (int.Parse(mo["DriveType"].ToString()))
            {
               case Removable: //Removable Drives
               imageIndex = 5;
               selectIndex = 5;
               break;
               case LocalDisk: //硬盘
               imageIndex = 6;
               selectIndex = 6;
               break;
               case CD: //光驱
               imageIndex = 7;
               selectIndex = 7;
               break;
               case Network: //网络磁盘
               imageIndex = 8;
               selectIndex = 8;
               break;
               default: //预设显示目录图标
               imageIndex = 2;
               selectIndex = 3;
               break;
            }
            
            //建立驱动器
            nodeTemp = new TreeNode(mo["Name"].ToString() + "\\", imageIndex, selectIndex);
            nodeCollection.Add(nodeTemp);
         }
         
         this.Cursor = Cursors.Default;
      }
      
      private void tvFolders_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
      {
         this.Cursor = Cursors.WaitCursor;
         TreeNode nodeCurrent = e.Node;
         nodeCurrent.Nodes.Clear();
         if (nodeCurrent.SelectedImageIndex == 0)
         LoadDrives();
         else
         LoadDirectory(nodeCurrent, nodeCurrent.Nodes);
         this.Cursor = Cursors.Default;
      }
      
      protected void LoadListView()
      {
         lvFiles.Clear();
         
         //创建ListView的标题列
         lvFiles.Columns.Add("Name", 150, System.Windows.Forms.HorizontalAlignment.Left);
         lvFiles.Columns.Add("Size", 75, System.Windows.Forms.HorizontalAlignment.Right);
         lvFiles.Columns.Add("Created", 140, System.Windows.Forms.HorizontalAlignment.Left);
         lvFiles.Columns.Add("Modified", 140, System.Windows.Forms.HorizontalAlignment.Left);
         
      }
      
      protected void LoadDirectory(TreeNode nodeCurrent, TreeNodeCollection nodeCurrentCollection)
      {
         TreeNode nodeTemp = null;
         
         int imageIndex = 2; //当前结点的图片
         int selectIndex = 3; //选中结点时显示的图片
         
         if (nodeCurrent.SelectedImageIndex != 0)
         {
            try
            {
               if (Directory.Exists(FormatPath(nodeCurrent.FullPath)) == false)
               throw new Exception("目录或路路径不存在!");
               
               LoadFiles(nodeCurrent);
               
               string[] stringDirectories = Directory.GetDirectories(FormatPath(nodeCurrent.FullPath));
               string stringFullPath = "";
               string stringPathName = "";
               
               //加载当前目录下所有子目录
               foreach (string stringDir in stringDirectories)
               {
                  stringFullPath = stringDir;
                  stringPathName = GetPathName(stringFullPath);
                  
                  TreeNode nodeDir = new TreeNode(stringPathName.ToString(), imageIndex, selectIndex);
                  nodeCurrentCollection.Add(nodeDir);
               }
            }
            catch (Exception e)
            {
               MessageBox.Show(e.Message);
            }
         }
      }
      
      protected string GetPathName(string stringPath)
      {
         string[] stringSplit = stringPath.Split(’\\’);
         return stringSplit[stringSplit.Length - 1];
      }
      
      //加载当前目录下的文件
      protected void LoadFiles(TreeNode nodeCurrent)
      {
         string[] listviewData = new string[4];
         this.LoadListView();
         
         if (nodeCurrent.SelectedImageIndex != 0)
         {
            if (Directory.Exists((string)FormatPath(nodeCurrent.FullPath)) == false)
            throw new Exception("目录或路路径不存在!");
            
            try
            {
               string[] stringFiles = Directory.GetFiles(FormatPath(nodeCurrent.FullPath));
               DateTime dtCreateDate, dtModifyDate;
               Int64 lFileSize = 0;
               
               foreach (string stringFile in stringFiles)
               {
                  FileInfo objFileSize = new FileInfo(stringFile);
                  lFileSize = objFileSize.Length;
                  dtCreateDate = objFileSize.CreationTime;
                  dtModifyDate = objFileSize.LastWriteTime;
                  
                  listviewData[0] = GetPathName(stringFile);
                  listviewData[1] = FormatSize(lFileSize);
                  
                  if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(dtCreateDate) == false)
                  listviewData[2] = FormatDate(dtCreateDate.AddHours(1));
                  else
                  listviewData[2] = FormatDate(dtCreateDate);
                  
                  if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(dtModifyDate) == false)
                  listviewData[3] = FormatDate(dtModifyDate.AddHours(1));
                  else
                  listviewData[3] = FormatDate(dtModifyDate);
                  
                  ListViewItem lvItem = new ListViewItem(listviewData, 0);
                  lvFiles.Items.Add(lvItem);
               }
            }
            catch (Exception e)
            {
               MessageBox.Show(e.Message);
            }
         }
      }
      
      //替代Root是My Computer
      protected string FormatPath(string stringPath)
      {
         string stringParse = stringPath.Replace("My Computer\\", "");
         return stringParse;
      }
      
      //获取所有磁盘驱器
      protected ManagementObjectCollection GetDriveList()
      {
         ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk ");
         ManagementObjectCollection queryCollection = query.Get();
         return queryCollection;
      }
      
      //转换为短日期格式
      protected string FormatDate(DateTime dtDate)
      {
         string stringDate = "";
         stringDate = dtDate.ToShortDateString().ToString() + " " + dtDate.ToShortTimeString().ToString();
         return stringDate;
      }
      
      
      //将文件大小转换为带KB的字符串
      protected string FormatSize(Int64 lSize)
      {
         string stringSize = "";
         NumberFormatInfo numInfo = new NumberFormatInfo();
         
         if (lSize < 1024) //小于1KB
         {
            if (lSize == 0)
            stringSize = "0";
            else
            stringSize = "1";
         }
         else
         {
            Int64 lKBSize = lSize / 1024; //转折为MB / 1024
            stringSize = lKBSize.ToString("n", numInfo);
            stringSize = stringSize.Replace(".00", "");
         }
         return stringSize + " KB";
      }
   }
}


Source Code:
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
C/S框架网
上一篇:架构C#WebService程序
下一篇:OOP设计思想之教学设备系统.附UML图.(一)
评论列表

发表评论

评论内容
昵称:
关联文章

C# Mini版本文件浏览器.TreeView/ListView应用
C#用ListView实现XP分组样式(图)
C#.NET TreeView拖拽功能(Drag,Drop)
C#获取应用程序当前文件目录位置(安装路径)
网站下载Mini Demo无法运行,登录界面提示错误
使用默认IE浏览器打开指定的URL网页
VS Winform设置应用程序文件图标及任务栏显示图标|C/S框架网
C#应用程序不需要管理员权限运行app.manifest文件配置
C/S框架新功能:自动检测升级包并强制关闭应用程序进行版本升级
C# TreeView组件TreeNode节点自动勾选解决方案(TreeViewNodeCheckHander)
VSCode设置默认浏览器打开网站
C#文件拖放操作(DragDrop File)
C#.Net版本自动更新程序及3种策略实现
C#.Net局域网版本自动升级解决方案(原创)
CSFramework_Mini 数据库结构 - Winform 蝇量框架
Mini-Framework蝇量框架 - 产品报价(全部源码)
WebService, WCF, WebApi 的区别与应用|C/S框架网推荐文档
IE浏览器监控程序-监控IE窗体URL动态加载网页等信息
CSFramework软件版本自动升级程序 - 系统配置文件 (UpgraderClient.ini)
CS开发框架版本介绍(www.csframework.com)

热门标签
软件著作权登记证书 .NET .NET Reactor .NET5 .NET6 .NET7 .NET8 .NET9 .NETFramework APP AspNetCore AuthV3 Auth-软件授权注册系统 Axios B/S B/S开发框架 B/S框架 BSFramework Bug Bug记录 C#加密解密 C#源码 C/S CHATGPT CMS系统 CodeGenerator CSFramework.DB CSFramework.EF CSFramework.License CSFrameworkV1学习版 CSFrameworkV2标准版 CSFrameworkV3高级版 CSFrameworkV4企业版 CSFrameworkV5旗舰版 CSFrameworkV6.0 CSFrameworkV6.1 CSFrameworkV6旗舰版 DAL数据访问层 Database datalock DbFramework Demo教学 Demo实例 Demo下载 DevExpress教程 Docker Desktop DOM ECS服务器 EFCore EF框架 Element-UI EntityFramework ERP ES6 Excel FastReport GIT HR IDatabase IIS JavaScript LINQ MES MiniFramework MIS MySql NavBarControl NETCore Node.JS NPM OMS Oracle资料 ORM PaaS POS Promise API PSD RedGet Redis RSA SAP Schema SEO SEO文章 SQL SQLConnector SQLite SqlServer Swagger TMS系统 Token令牌 VS2022 VSCode VS升级 VUE WCF WebApi WebApi NETCore WebApi框架 WEB开发框架 Windows服务 Winform 开发框架 Winform 开发平台 WinFramework Workflow工作流 Workflow流程引擎 XtraReport 安装环境 版本区别 报表 备份还原 踩坑日记 操作手册 达梦数据库 代码生成器 迭代开发记录 功能介绍 国际化 基础资料窗体 架构设计 角色权限 开发sce 开发工具 开发技巧 开发教程 开发框架 开发平台 开发指南 客户案例 快速搭站系统 快速开发平台 框架升级 毛衫行业ERP 秘钥 密钥 权限设计 软件报价 软件测试报告 软件加壳 软件简介 软件开发框架 软件开发平台 软件开发文档 软件授权 软件授权注册系统 软件体系架构 软件下载 软件著作权登记证书 软著证书 三层架构 设计模式 生成代码 实用小技巧 视频下载 收钱音箱 数据锁 数据同步 微信小程序 未解决问题 文档下载 喜鹊ERP 喜鹊软件 系统对接 详细设计说明书 新功能 信创 行政区域数据库 需求分析 疑难杂症 蝇量级框架 蝇量框架 用户管理 用户开发手册 用户控件 在线支付 纸箱ERP 智能语音收款机 自定义窗体 自定义组件 自动升级程序
联系我们
联系电话:13923396219(微信同号)
电子邮箱:23404761@qq.com
站长微信二维码
微信二维码