public DriveInfoProgress(MainForm owner, DriveInfoData driveInfoData) { if (driveInfoData == null) { throw new ArgumentNullException("driveInfoWrapper"); } InitializeComponent(); _owner = owner; _driveInfoData = driveInfoData; _driveInfoData.ProgressChanged += _driveInfoWrapper_ProgressChanged; Volume = _driveInfoData.Volume; label1.Text = Volume; SetStatus(DriveInfoProgressStatus.Ready); _bgw = new BackgroundWorker() { WorkerReportsProgress = true, WorkerSupportsCancellation = true }; _bgw.DoWork += bgw_DoWork; _bgw.ProgressChanged += bgw_ProgressChanged; _bgw.RunWorkerCompleted += bgw_RunWorkerCompleted; StartCopy(); }
private void _drives_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { var oldItems = e.OldItems != null?e.OldItems.Cast <DriveInfo>() : Enumerable.Empty <DriveInfo>(); foreach (var rmvItem in oldItems) { ThreadSafeWinControlHelper.RemoveDriveInfoWrapper(flowLayoutPanel1, rmvItem.Name); } var newItems = e.NewItems != null?e.NewItems.Cast <DriveInfo>() : Enumerable.Empty <DriveInfo>(); foreach (var addItem in newItems) { var t = new Thread((ThreadStart) delegate { DetectDriveDisconnectThread(addItem); }) { Name = string.Format("ThumbDriveDuplicatorDisconnect;{0}", addItem.RootDirectory.FullName), IsBackground = true }; t.Start(); var driveWrapper = new DriveInfoData(addItem); ThreadSafeWinControlHelper.AddDriveInfoWrapper(this, flowLayoutPanel1, driveWrapper); } }
public static void AddDriveInfoWrapper(MainForm owner, FlowLayoutPanel panel, DriveInfoData driveInfo) { if (panel.InvokeRequired) { panel.Invoke(new AddDriveInfoWrapperDelegate(AddDriveInfoWrapper), owner, panel, driveInfo); } else { var control = new DriveInfoProgress(owner, driveInfo); //control.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right))); control.Width = panel.Width - 10; control.Left = 5; control.Top = (panel.Controls.Count * control.Height) + 4; panel.Controls.Add(control); panel.PerformLayout(); } }