private static void InvokeSwitchStyle(MetroForm form) { var switchFormStyleMethod = form.GetType().GetMethod("SwitchFormStyle"); if (switchFormStyleMethod != null) { switchFormStyleMethod.Invoke(form, null); } }
protected virtual void ClickMouseDown(object sender, MouseEventArgs e) { var grid = (DataGridView)sender; int rowIndex = grid.HitTest(e.X, e.Y).RowIndex; SelectedRowIndex = rowIndex; if (rowIndex == -1) { grid.ClearSelection(); } else { grid.Rows[rowIndex].Selected = true; } if (e.Button == MouseButtons.Right) { string id = ""; var isSelected = grid.SelectedRows.Count > 0; if (isSelected) { var row = grid.SelectedRows[0]; id = row.Cells["Id"].Value.ToString(); } Menu = new ContextMenu(); var menuNew = new MenuItem { Text = "Новая запись" }; menuNew.Click += NewClick; var menuEdit = new MenuItem { Text = "Редактировать запись", Enabled = isSelected }; menuEdit.Click += (o, args) => UpdateClick(o, args, id); var menuDelete = new MenuItem { Text = "Удалить запись", Enabled = isSelected }; menuDelete.Click += (o, args) => DeleteClick(o, args, id); var menuRefresh = new MenuItem { Text = "Обновить список" }; menuRefresh.Click += RefreshClick; var menuSearch = new MenuItem { Text = "Поиск" }; menuSearch.Click += (o, args) => MainForm.GetType().GetMethod("SearchInGrid").Invoke(MainForm, null); Menu.MenuItems.Add(menuNew); Menu.MenuItems.Add(menuEdit); Menu.MenuItems.Add(menuDelete); Menu.MenuItems.Add(menuRefresh); Menu.MenuItems.Add(menuSearch); AdditionalMenuItems(isSelected, id); ContextMenu = Menu; ContextMenu.Show(this, e.Location); } }