C#获取文件类型
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FileStyle
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void listView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy; //设置拖放操作中目标放置类型为复制
String[] str_Drop = (String[])e.Data.GetData(DataFormats.FileDrop, true);//检索数据格式相关联的数据
Data_List(listView1, str_Drop[0]);
}
public void Data_List(ListView LV, string F) //Form或MouseEventArgs添加命名空间using System.Windows.Forms;
{
string enlarge = "";
if (F.LastIndexOf(".") == F.Length - 4)
{
enlarge = F.Substring(F.LastIndexOf(".") + 1, 3);
}
ListViewItem item = new ListViewItem(F);
item.SubItems.Add(enlarge);
LV.Items.Add(item);
}
private void Form1_Shown(object sender, EventArgs e)
{
listView1.GridLines = true;//在各数据之间形成网格线
listView1.View = View.Details;//显示列名称
listView1.FullRowSelect = true;//在单击某项时,对其进行选中
listView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;//隐藏列标题
listView1.Columns.Add("文件名", listView1.Width - 65, HorizontalAlignment.Right);//设置头像
listView1.Columns.Add("类型", 60, HorizontalAlignment.Center);//设置头像
}
}
}
Form1.Designer.cs
namespace FileStyle
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// listView1
//
this.listView1.AllowDrop = true;
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.Location = new System.Drawing.Point(0, 0);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(292, 253);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView1_DragEnter);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 253);
this.Controls.Add(this.listView1);
this.Name = "Form1";
this.Text = "获取文件的类型";
this.Shown += new System.EventHandler(this.Form1_Shown);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListView listView1;
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace FileStyle
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
C#获取文件类型的更多相关文章
- java读取resource/通过文件名获取文件类型
java读取resource java读取resource目录下文件的方法: 借助Guava库的Resource类 Resources.getResource("test.txt" ...
- readdir() 获取文件类型
readdir()获取文件类型 //// 字符设备文件 type =2, filename207=tty0 crw-rw---- 1 root root 4, 0 04-10 16:28 ...
- delphi 动态获取文件类型的图标
delphi 动态获取文件类型的图标.txt我不奢望什么,只希望你以后的女人一个不如一个.真怀念小时候啊,天热的时候我也可以像男人一样光膀子!在应用程序的编写中,组合框(ComboBox).列表框(L ...
- 利用Python获取文件类型
这里选择使用使用filetype获取文件的类型. 使用filetype之前,先用pip安装filetype. #!/usr/bin/python3 import filetype import arg ...
- C#文件拖放至窗口的ListView控件获取文件类型
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Winform中实现拖拽文件到ListView获取文件类型(附代码下载)
场景 效果 注: 博客主页: https://blog.csdn.net/badao_liumang_qizhi关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 新建一个for ...
- python 快速获取文件类型
- Python 获取文件类型后缀
import os path='file.txt' file=os.path.splitext(path) filename,type=file print(filename) print(type)
- 获取pe文件的文件类型
工程文件petype.cpp通过调用pefile类中的函数获取文件类型. 文件类型的判断通过5个监测点完成. 监测点1:dos头的e_magic 监测点2:nt头的Signature 监测点3:文件头 ...
随机推荐
- pypi上传问题
pypi上传过程中报错403 windows 解决办法: 1.建一个新的记事本编辑内容 [distutils]index-servers = pypi [pypi]repository:https:/ ...
- 创建servlet程序知识点详解---servlet-day03
#1.表单包含有中文参数值,如何处理? ##(1)为什么会有乱码? 表单提交时,浏览器会对中文参数值进行编码/ 注:会按照表单所有的页面打开时所使用的字符集进行编码 比如,浏览器会使用utf-8对中文 ...
- Web_Toy
1 2 3 4 1.App录音 var r = plus.audio.getRecorder() # 创建录音对象 r.record({filename:"_doc/audio/" ...
- centos6安装配置zabbix3主控端
Centos 6.5 Zabbix 3.0.4 zabbix分为zabbix-server(主控端)和zabbix-agent(被控端),本文只介绍server: 安装mysql mysql建议使用5 ...
- 【题解】JSOIWC2019 Round1
题面(T1变成5s(毒瘤出题人发现std超时了qaq)): 啥都不会qaq.但也送了不少分 题解: T1: 当T=0时直接异或前缀和,但T=1时就有点恶心 暴力能有80pts(防止大家爆零) 还珂以用 ...
- 01:golang开发环境
1.1 go环境安装 1.go下载安装 官方:https://golang.org/dl 国内: https://golang.google.cn/dl/ https://www.golangtc.c ...
- java中什么是泛型
一. 泛型概念的提出(为什么需要泛型)? 首先,我们看下下面这段简短的代码: 1 public class GenericTest { 2 3 public static void main(Stri ...
- C#树类型及其遍历
最近有个项目不仅需要取部门的层级关系,还要处理不规则的关系(移除某个部门),只有树结构才能实现相关遍历和操作. 涉及到的知识点:泛型.递归.数据结构 既然研究树类型就先来看下树的定义: 一棵树(tre ...
- CSS布局学习(三) - position属性定义及解释(官网直译)
static ①元素的位置是在文档正常布局流中的位置. ②设置top right bottom left与z-index无效. ③在未指定position时,static是默认值 以下例子进行说明: ...
- [原][算法][earth]三段smooth,传入时间,返回距离。仿谷歌视角飞跃处理
算法需求: 传入[0~1]的时间time,返回[0~1]的路程. 整个路程distance[0~1]分为三段路径: 第一段:在0.25time的时间里,速度从0,位置从distance:0加速移动到距 ...