本文整理汇总了C#中System.Windows.Forms.ListViewItem.Select方法的典型用法代码示例。如果您正苦于以下问题:C# ListViewItem.Select方法的具体用法?C# ListViewItem.Select怎么用?C# ListViewItem.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListViewItem
的用法示例。
在下文中一共展示了ListViewItem.Select方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddTrackTypesMenuItems
private void AddTrackTypesMenuItems(ContextMenuStrip menu, ListViewItem[] selectedListViewItems)
{
var tracks = selectedListViewItems.Select(item => item.Tag as Track).ToArray();
var allTrackTypes = Enum.GetValues(typeof(TrackType)).OfType<TrackType>().ToArray();
var selectedTrackTypes = new HashSet<TrackType>();
foreach (var track in tracks)
{
selectedTrackTypes.Add(track.Type);
}
var selectedTrackType = selectedTrackTypes.Count == 1 ? new TrackType?(selectedTrackTypes.First()) : null;
foreach (var trackType in allTrackTypes)
{
var type = trackType;
var menuItem = new ToolStripMenuItem(trackType.ToString());
if (selectedTrackType.HasValue && selectedTrackType == trackType)
{
menuItem.Checked = true;
menuItem.Enabled = false;
}
menuItem.Click += (s, e) => TrackTypeMenuItemOnClick(selectedListViewItems, type);
menu.Items.Add(menuItem);
}
}
示例2: UIEventHandlers
private void UIEventHandlers()
{
// Drag Drop Files
lvPreview.DragEnter += (@s, a) =>
{
if (a.Data.GetDataPresent(DataFormats.FileDrop))
a.Effect = DragDropEffects.Link;
};
lvPreview.DragDrop += (@s, e) =>
{
String[] files = (String[]) e.Data.GetData(DataFormats.FileDrop);
Session.AddFile(files);
UpdatePreview();
};
// Resize
lvPreview.Resize += (@s, a) =>
{
Int32 width = (lvPreview.Width - 48) / 2;
lvPreview.Columns[0].Width = width;
lvPreview.Columns[1].Width = width;
};
lvPreview.KeyDown += (@s, e) =>
{
if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control)
{
foreach (ListViewItem i in lvPreview.Items)
i.Selected = true;
}
else if (e.KeyCode == Keys.Delete)
{
ListViewItem[] items = new ListViewItem[lvPreview.SelectedItems.Count];
lvPreview.SelectedItems.CopyTo(items, 0);
Session.RemoveFiles(from i in items select (String)i.Tag);
UpdatePreview();
}
};
// Context Menus
lvPreview.ItemSelectionChanged += (@s, e) =>
{
Int32 count = lvPreview.SelectedItems.Count;
tsmiPvRemSelection.Enabled = count > 0;
tsmiPvExtractRule.Enabled = count == 1;
};
lvRules.ItemSelectionChanged += (@s, e) =>
{
Int32 count = lvRules.SelectedItems.Count;
tsmiRemoveRules.Enabled = count > 0;
tsmiAddToTemplates.Enabled = count == 1;
};
tsmiAddRule.Click += (@s, e) =>
{
RuleEditorDialog dlg = new RuleEditorDialog(this);
if (dlg.ShowDialog() == DialogResult.OK)
{
RenamingRule rule = dlg.Rule;
Session.Rules.AddRule(rule);
}
};
tsmiRemoveRules.Click += (@s, e) =>
{
ListViewItem[] selection = new ListViewItem[lvRules.SelectedItems.Count];
lvRules.SelectedItems.CopyTo(selection, 0);
foreach (RenamingRule rule in selection.Select(v => v.Tag).OfType<RenamingRule>())
Session.Rules.RemoveRule(rule);
UpdateUI();
};
tsmiAddToTemplates.Click += (@s, e) =>
{
RenamingRule rule = lvRules.SelectedItems[0].Tag as RenamingRule;
if (rule == null) throw new Exception();
OptionsDialog dlg = new OptionsDialog(1, rule);
dlg.ShowDialog();
UpdateUI();
};
tsmiPvAddFiles.Click += (@s, e) =>
{
OpenFileDialog dlg = new OpenFileDialog() { Multiselect = true };
if (dlg.ShowDialog() == DialogResult.OK)
Session.AddFile(dlg.FileNames);
};
tsmiPvRemSelection.Click += (@s, e) =>
{
ListViewItem[] items = new ListViewItem[lvPreview.SelectedItems.Count];
lvPreview.SelectedItems.CopyTo(items, 0);
Session.RemoveFiles(from i in items select (String)i.Tag);
UpdatePreview();
};
tsmiPvExtractRule.Click += (@s, e) =>
{
String fname = lvPreview.SelectedItems[0].Tag as String;
if (fname == null) return;
//.........这里部分代码省略.........
示例3: AddLanguagesMenuItem
private void AddLanguagesMenuItem(ContextMenuStrip menu, ListViewItem[] listViewItems)
{
// Only allow users to change the language on video tracks
var tracks = listViewItems.Select(item => item.Tag as Track).ToArray();
var isVideo = tracks.All(track => track.IsVideo);
if (!isVideo)
return;
var selectedLanguages = new HashSet<Language>();
foreach (var track2 in tracks)
{
selectedLanguages.Add(track2.Language);
}
var selectedLanguage = selectedLanguages.Count == 1 ? selectedLanguages.FirstOrDefault() : null;
var languagesMenuItem = new ToolStripMenuItem("Language");
foreach (var language in _allLanguages.OrderBy(language => language.Name))
{
var lang = language;
var langMenuItem = new ToolStripMenuItem(language.Name);
langMenuItem.Click += (s, e) => LanguageMenuItemOnClick(listViewItems, lang);
if (language.Equals(selectedLanguage))
{
langMenuItem.Checked = true;
langMenuItem.Enabled = false;
}
languagesMenuItem.DropDownItems.Add(langMenuItem);
}
menu.Items.Add(languagesMenuItem);
menu.Items.Add("-");
}
示例4: RenamingTabAttachEventHandlers
private void RenamingTabAttachEventHandlers()
{
renBtnAddRule.Click += (@s, e) =>
{
RuleEditorDialog dlg = new RuleEditorDialog(this);
if (dlg.ShowDialog() == DialogResult.OK)
{
RenamingRule rule = dlg.Rule;
rule.Active = true;
switch (rule.Type)
{
case RenamingRule.RuleType.Name:
{
Session.Rules.NameRules.Add(rule);
}
break;
case RenamingRule.RuleType.Extension:
{
Session.Rules.ExtensionRules.Add(rule);
}
break;
case RenamingRule.RuleType.Directory:
{
Session.Rules.DirectoryRules.Add(rule);
}
break;
}
UpdateUI();
}
};
renBtnRemoveRule.Click += (@s, e) =>
{
ListViewItem[] selection = new ListViewItem[lvRules.SelectedItems.Count];
lvRules.SelectedItems.CopyTo(selection, 0);
foreach (RenamingRule rule in selection.Select(v => v.Tag).OfType<RenamingRule>())
{
if (rule.Type == RenamingRule.RuleType.Name)
Session.Rules.NameRules.Remove(rule);
else if (rule.Type == RenamingRule.RuleType.Extension)
Session.Rules.ExtensionRules.Remove(rule);
else
Session.Rules.DirectoryRules.Remove(rule);
}
UpdateUI();
};
lvRules.ItemChecked += (@s, a) =>
{
RenamingRule rule = a.Item.Tag as RenamingRule;
if (rule == null) return;
if (rule.Active != a.Item.Checked)
{
rule.Active = a.Item.Checked;
UpdatePreview();
}
};
}