Detects insertion or removal of removable drives. Use it in 1 or 2 steps: 1) Create instance of this class in your project and add handlers for the DeviceArrived, DeviceRemoved and QueryRemove events. AND (if you do not want drive detector to creaate a hidden form)) 2) Override WndProc in your form and call DriveDetector's WndProc from there. If you do not want to do step 2, just use the DriveDetector constructor without arguments and it will create its own invisible form to receive messages from Windows.
상속: IDisposable
예제 #1
0
 /// <summary>
 /// Set up the hidden form.
 /// </summary>
 /// <param name="detector">DriveDetector object which will receive notification about USB drives, see WndProc</param>
 public DetectorForm(DriveDetector detector)
 {
     mDetector            = detector;
     this.MinimizeBox     = false;
     this.MaximizeBox     = false;
     this.ShowInTaskbar   = false;
     this.ShowIcon        = false;
     this.FormBorderStyle = FormBorderStyle.None;
     this.Load           += new System.EventHandler(this.Load_Form);
     this.Activated      += new EventHandler(this.Form_Activated);
 }
예제 #2
0
        public ItemsViewer()
        {
            InitializeComponent();

            GetDriveInfo(cbDrive);

            history.Clear();

            Dolinay.DriveDetector driveDetector = new Dolinay.DriveDetector();
            driveDetector.DeviceArrived += new DriveDetectorEventHandler(OnDriveArrived);
            driveDetector.DeviceRemoved += new DriveDetectorEventHandler(OnDriveRemoved);
        }
예제 #3
0
        /// <summary>
        /// Set up the hidden form.
        /// </summary>
        /// <param name="detector">DriveDetector object which will receive notification about USB drives, see WndProc</param>
        public DetectorForm(DriveDetector detector)
        {
            mDetector     = detector;
            Size          = new System.Drawing.Size(5, 5);
            BackColor     = System.Drawing.Color.Black;
            WindowState   = FormWindowState.Minimized;
            ShowInTaskbar = false;

            // NOTA: Se anula parte del código (en especial los eventos) porque por alguna razón al ejecutar un form que
            //       utilice esta clase, a veces, el form abierto pierde el foco en favor de otras aplicaciones abiertas
            //       en Windows. Ej: Al ejecutar ProgramadorCS sube arriba Google Chrome

            //this.MinimizeBox = false;
            //this.MaximizeBox = false;
            //this.ShowIcon = false;
            //this.FormBorderStyle = FormBorderStyle.None;
            //this.Load += new System.EventHandler(this.Load_Form);
            //this.Activated += new EventHandler(this.Form_Activated);
        }