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:文件头 ...
随机推荐
- python locust 性能测试:locust 参数化(list) ---循环取数据,数据可重复使用
from locust import TaskSet, task, HttpLocust class UserBehavior(TaskSet): def on_start(self): # 当模拟用 ...
- 浅探网络1---tcp协议详解(三次握手和四次挥手)
TCP协议是网络多层协议中运输层的最重要的协议之一,运输层是两台主机的进程之间的通信.除了TCP还有一个是UDP协议(用户数据包协议) TCP全称是Transmission Control Proto ...
- Why Choose MB SD C5 with Engineer Software
MB SD C5 with engineer software performed good and now is released. Unlike the old clone C5 which us ...
- Html textarea 标签
Html textarea 标签 </body> </html> <!-- textarea 标签输入多行文本框,name="xxx"标识后端获取名称 ...
- Docker+Jenkins+Maven+SVN搭建持续集成环境
Docker+Jenkins+Maven+SVN搭建持续集成环境 环境拓扑图(实验项目使用PHP环境) 发布流程图 环境说明 系统:Centos 7.4 x64 Docker版本:18.09.0 Ma ...
- Python3 tkinter基础 Menu add_checkbutton 多选的下拉菜单
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 基于token的身份验证JWT
传统身份验证的方法 HTTP 是一种没有状态的协议,也就是它并不知道是谁是访问应用.这里我们把用户看成是客户端,客户端使用用户名还有密码通过了身份验证,不过下回这个客户端再发送请求时候,还得再验证一下 ...
- UVA11235 Frequent values
思路 连续的值只会分布在一起成一个块 讨论两边的块,中间就是RMQ了 ST表即可 代码 #include <cstdio> #include <algorithm> #incl ...
- CSS【03】:CSS 基础选择器与三种引入方式
基础选择器 选择器:css 选择 html 标签的一个工具,是将 css 与 html 建立起联系,那么 css 就可以控制 html 样式 选择器其实就是给 html 标签起名字 标签选择器 作用: ...
- css 简介 2
css css Table属性 border-collapse 设置是否把表格边框合并为单一的边框 border-spacing 设置表格标题的位置 empty-cells 设置是否显示表格中的空单元 ...