Form1.cs

(完整代码) 1KB

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;
using Test.TestCase;

namespace USBListenerWindowsForms
{
    public partial class Form1 : Form
    {
        DriveDetector detector = new DriveDetector();
        public Form1()
        {
            InitializeComponent();
        }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            detector.WndProc(m.HWnd, m.Msg, m.WParam, m.LParam);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var drivers = DriveDetector.GetDeviceRootDir("U");
            if (drivers != null && drivers.Count > 0)
            {
                label1.BeginInvoke(new Action(() =>
                {
                    label1.Text = "USB设备已连接";
                }));
            }


            detector.DeviceArrived += (o, evt) =>
            {
                label1.BeginInvoke(new Action(() =>
                {
                    label1.Text = "USB设备已连接";
                }));
            };

            detector.DeviceRemoved += (o, evt) =>
            {
                label1.BeginInvoke(new Action(() =>
                {
                    label1.Text = "USB设备断开连接";
                }));
            };
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。