下面我通过一个小例子并结合一段代码片段给大家展示下,有需要的朋友可以来借鉴下。
界面上拖一个 button 和treeview ,运行的时候直接插入优盘,单机按钮就会出现目录文件。不过只能在u盘插入,U盘拔出时,才能接收到信息。
1.[C#]代码
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace usbText
{
public partial class Form1 : Form
{
DriveInfo Tdriver = null;
public Form1()
{
InitializeComponent();
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0219)//WM_DEVICECHANGE
{
switch