private void contextMenuStrip_Opened(object sender, EventArgs e) { bool canStart = false; bool canPause = false; bool canCancel = false; if (listView.SelectedItems.Count > 0) { canCancel = true; } foreach (ListViewItem item in listView.SelectedItems) { Downloader.Download download = item.Tag as Downloader.Download; if (download.IsRunning) { canPause = true; } else { canStart = true; } } startToolStripMenuItem.Enabled = canStart; pauseToolStripMenuItem.Enabled = canPause; cancelToolStripMenuItem.Enabled = canCancel; }
private void cancelToolStripMenuItem_Click(object sender, EventArgs e) { foreach (ListViewItem item in listView.SelectedItems) { Downloader.Download download = item.Tag as Downloader.Download; download.Cancel(); } UpdateView(); }
private void pauseToolStripMenuItem_Click(object sender, EventArgs e) { foreach (ListViewItem item in listView.SelectedItems) { Downloader.Download download = item.Tag as Downloader.Download; if (download.IsRunning) { download.Stop(); } } UpdateView(); }