private void SetCheckBoxItem(CheckedListBox checkbox) { for (int i = 0; i < checkbox.Items.Count; i++) { if (checkbox.GetItemRectangle(i).Contains(checkbox.PointToClient(MousePosition))) { switch (checkbox.GetItemCheckState(i)) { case CheckState.Checked: checkbox.SetItemCheckState(i, CheckState.Unchecked); break; case CheckState.Indeterminate: case CheckState.Unchecked: checkbox.SetItemCheckState(i, CheckState.Checked); break; } } } }
private void DoProfileCheckDown(object sender, MouseEventArgs e) { CheckedListBox targetBox = sender as CheckedListBox; Point loc = targetBox.PointToClient(Cursor.Position); for (int i = 0; i < targetBox.Items.Count; i++) { Rectangle rec = targetBox.GetItemRectangle(i); rec.Width = 16; if (rec.Contains(loc)) { _authorizeCheckBehavior = true; bool newValue = !targetBox.GetItemChecked(i); targetBox.SetItemChecked(i, newValue); _authorizeCheckBehavior = false; return; } } }
public static CheckedListBox ShowCheckBoxes(string[] options, string caption, int w, int h, int wc = 110, int hc = 300) { Form prompt = new Form() { AutoSize = true, Width = w, Height = h, FormBorderStyle = FormBorderStyle.FixedDialog, Text = caption, StartPosition = FormStartPosition.CenterParent, ControlBox = false, AutoScaleMode = AutoScaleMode.Font, AutoSizeMode = AutoSizeMode.GrowOnly }; FlowLayoutPanel pnl = new FlowLayoutPanel { Dock = DockStyle.Fill, Visible = true, Name = caption, TabIndex = 0, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowOnly, FlowDirection = FlowDirection.TopDown }; CheckedListBox cb = new CheckedListBox(); cb.ItemCheck += Cb_ItemCheck; cb.CheckOnClick = true; cb.Items.AddRange(options); cb.IntegralHeight = true; cb.SetItemCheckState(0, CheckState.Checked); for (int i = 1; i < cb.Items.Count; i++) { cb.SetItemChecked(i, false); cb.GetItemRectangle(i); //This is required for GetPreferredSize to function. Very confusing. } Button toggleAllSelection = new Button() { Anchor = AnchorStyles.Right, Dock = DockStyle.Top, Text = "Select/Deselect All", Left = 350, Width = 100, Top = 70, AutoSize = true }; toggleAllSelection.Click += (sender, e) => { bool isChecked = false; for (int i = 1; i < cb.Items.Count && isChecked == false; i++) { isChecked = cb.GetItemChecked(i); } for (int i = 1; i < cb.Items.Count; i++) { cb.SetItemChecked(i, !isChecked); } }; pnl.Controls.Add(toggleAllSelection); cb.ClientSize = cb.GetPreferredSize(new System.Drawing.Size()); pnl.Controls.Add(cb); Button confirmation = new Button() { Anchor = AnchorStyles.Right, Dock = DockStyle.Bottom, Text = "OK", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK, AutoSize = true }; confirmation.Click += (sender, e) => { prompt.Close(); }; pnl.Controls.Add(confirmation); prompt.AcceptButton = confirmation; prompt.Controls.Add(pnl); prompt.ShowDialog(); return(cb); }
public static DialogResult ShowDialog(IWin32Window window) { Form prompt = new Form() { Width = 220, Height = 200, FormBorderStyle = FormBorderStyle.FixedDialog, Text = "Add Filter", StartPosition = FormStartPosition.CenterScreen, MinimizeBox = false, MaximizeBox = false }; Label consoleNameLabel = new Label() { Left = 18, Top = 20, Text = "Select Console" }; var consoleSelector = new ComboBox() { Left = 20, Top = 40, Width = 150 }; consoleSelector.Items.AddRange(Form1._consoleController.GetAllConsoles().Select(x => x.Name).ToArray()); consoleSelector.DropDownStyle = ComboBoxStyle.DropDownList; var fileExtensionChecklist = new CheckedListBox { Left = 20, Top = 103, Height = 30 }; var filterLabel = new Label { Left = 18, Top = 80, Width = 200, Text = "File Extensions:" }; consoleSelector.SelectedIndexChanged += (sender, e) => { selectedConsole = Form1._consoleController.GetAllConsoles().Where(x => x.Name == consoleSelector.Text).FirstOrDefault(); var roms = Form1._romController.GetRomsForConsole(selectedConsole, filtered: false); var extensions = roms.Select(x => x.Extension).Distinct().ToList(); fileExtensionChecklist.Items.Clear(); fileExtensionChecklist.Items.AddRange(extensions.ToArray()); var height = 15; if (fileExtensionChecklist.Items.Count > 0) { height = fileExtensionChecklist.GetItemRectangle(0).Height *fileExtensionChecklist.Items.Count; } fileExtensionChecklist.ClientSize = new Size(fileExtensionChecklist.ClientSize.Width, height); prompt.Height = (fileExtensionChecklist.Items.Count * 15) + 200; }; consoleSelector.SelectedIndexChanged += (sender, e) => { for (var i = 0; i < fileExtensionChecklist.Items.Count; i++) { if (!string.IsNullOrWhiteSpace(selectedConsole.Filter)) { if (selectedConsole.Filter.Contains(fileExtensionChecklist.GetItemText(fileExtensionChecklist.Items[i]))) { fileExtensionChecklist.SetItemChecked(i, true); } continue; } fileExtensionChecklist.SetItemChecked(i, true); } }; if (Form1.ActiveConsole != null) { consoleSelector.SelectedItem = consoleSelector.Items[consoleSelector.Items.IndexOf(Form1.ActiveConsole.Name)]; } Button saveFilterButton = new Button() { Text = "Save Filter", Left = 20, Width = 100, Top = prompt.Height - 70 }; saveFilterButton.Click += (sender, e) => { var error = false; if (fileExtensionChecklist.CheckedItems.Count == 0) { ShowError(fileExtensionChecklist, "At least 1 extension must be allowed"); error = true; } if (string.IsNullOrWhiteSpace(consoleSelector.Text)) { ShowError(consoleSelector, "Please select a Console"); error = true; } if (error) { return; } string fileExtensions = ""; foreach (var item in fileExtensionChecklist.CheckedItems) { fileExtensions += fileExtensionChecklist.GetItemText(item) + ','; } fileExtensions = fileExtensions.TrimEnd(','); Form1._consoleController.SaveFilterForConsole(selectedConsole, fileExtensions); prompt.DialogResult = DialogResult.OK; return; }; Button cancelButton = new Button() { Text = "Cancel", Left = 130, Width = 50, Top = prompt.Height - 70, DialogResult = DialogResult.Cancel }; prompt.ClientSizeChanged += (sender, e) => { cancelButton.Top = prompt.Height - 70; saveFilterButton.Top = prompt.Height - 70; }; prompt.Controls.Add(consoleSelector); prompt.Controls.Add(saveFilterButton); prompt.Controls.Add(cancelButton); prompt.Controls.Add(consoleNameLabel); prompt.Controls.Add(filterLabel); prompt.Controls.Add(fileExtensionChecklist); prompt.AcceptButton = saveFilterButton; prompt.CancelButton = cancelButton; return(prompt.ShowDialog()); }
public static string ShowDialog(IWin32Window window) { Form prompt = new Form() { Width = 500, Height = 50, FormBorderStyle = FormBorderStyle.FixedDialog, Text = "Add ROM Folder", StartPosition = FormStartPosition.CenterScreen, MinimizeBox = false, MaximizeBox = false }; var consoleNameLabel = new Label() { Left = 18, Top = 20, Text = "Select Console" }; var consoleSelector = new ComboBox() { Left = 20, Top = 40, Width = 150, DropDownStyle = ComboBoxStyle.DropDownList }; consoleSelector.Items.AddRange(Form1._consoleController.GetAllConsoles().Select(x => x.Name).ToArray()); var romFolderLabel = new Label() { Left = 18, Top = 80, Text = "Select ROM Folder" }; var romFolderSelector = new CheckedListBox { Left = 20, Top = 100, Width = 440 }; consoleSelector.SelectedIndexChanged += (sender, e) => { selectedConsole = Form1._consoleController.GetAllConsoles().First(x => x.Name == consoleSelector.Text); var romFolders = Form1._romFolderController.GetRomFoldersForConsole(selectedConsole).Select(x => x.Path).ToArray(); romFolderSelector.Items.Clear(); romFolderSelector.Items.AddRange(romFolders); var height = 15; if (romFolderSelector.Items.Count > 0) { height = romFolderSelector.GetItemRectangle(0).Height *romFolderSelector.Items.Count; } romFolderSelector.ClientSize = new Size(romFolderSelector.ClientSize.Width, height); prompt.Height = romFolderSelector.Height + 180; }; if (Form1.ActiveConsole != null) { consoleSelector.SelectedItem = consoleSelector.Items[consoleSelector.Items.IndexOf(Form1.ActiveConsole.Name)]; } var deleteButton = new Button() { Text = "Delete Selected", Left = 300, Width = 100, Top = prompt.Height - 70 }; deleteButton.Click += (sender, e) => { if (selectedConsole == null) { ShowError(consoleSelector, "Please select a Console"); return; } var romFolders = new List <Data.CuratorDataSet.RomFolderRow>(); foreach (var item in romFolderSelector.CheckedItems) { var path = romFolderSelector.GetItemText(item); romFolders.Add(Form1._romFolderController.GetRomFoldersForConsole(selectedConsole).FirstOrDefault(x => x.Path == path)); } if (romFolders.Count > 0) { var confirm = MetroMessageBox.Show(window, "Are you sure you want to delete these ROM Folders?", "ROM Folder Deletion", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (confirm == DialogResult.OK) { foreach (var romFolder in romFolders) { Form1._romFolderController.Remove(romFolder); } prompt.DialogResult = confirm; } } }; Button cancelButton = new Button() { Text = "Cancel", Left = 410, Width = 50, Top = prompt.Height - 70 }; prompt.ClientSizeChanged += (sender, e) => { cancelButton.Top = prompt.Height - 70; deleteButton.Top = prompt.Height - 70; }; prompt.Controls.Add(consoleSelector); prompt.Controls.Add(deleteButton); prompt.Controls.Add(cancelButton); prompt.Controls.Add(consoleNameLabel); prompt.Controls.Add(romFolderSelector); prompt.Controls.Add(romFolderLabel); prompt.AcceptButton = deleteButton; prompt.CancelButton = cancelButton; return(prompt.ShowDialog() == DialogResult.OK ? consoleSelector.Text : string.Empty); }