/// <summary> /// Open the 'More Color' dialog, that is, a normal ColorDialog control. /// </summary> /// <returns></returns> private Color OpenMoreColorsDialog() { colorDialog.Color = Color; Form parentForm = this.FindForm(); ContextMenuForm contextFrm = parentForm as ContextMenuForm; if (contextFrm != null) { // Ignore lost focus events on owner context menu form contextFrm.Locked = true; colorDialog.ShowDialog(contextFrm); // Give the focus back to owner form if (_parentControl != null) { _parentControl.FindForm().BringToFront(); } // Active lost focus events on owner context menu form contextFrm.Locked = false; } else { colorDialog.ShowDialog(this); // (parentForm); } return(colorDialog.Color); }
/// <summary> /// Overrides, when click on, handles color selection. /// </summary> /// <param name="e"></param> protected override void OnMouseClick(MouseEventArgs e) { base.OnMouseClick(e); // Check cursor, if on one of the buttons - hot track it for (int recIndex = 0; recIndex < buttons.Length; recIndex++) { if (buttons[recIndex].Contains(e.Location)) { _currentSelected = recIndex; // More colors - open dialog if (_currentSelected == 40) { Color = OpenMoreColorsDialog(); } else { Color = CustomColors.SelectableColors[recIndex]; colorToolTip.SetToolTip(this, CustomColors.SelectableColorsNames[recIndex]); } if (_contextForm != null) { _contextForm.Hide(); } _contextForm = null; } } this.Refresh(); }
/// <summary> /// Opens the control inside a context menu in the specified location /// </summary> /// <param name="startLocation">Screen coordinates location of the control</param> public void Show(Point startLocation) { // Creates new contextmenu form, adds the control to it, display it. _contextForm = new ContextMenuForm(); _contextForm.SetContainingControl(this); _contextForm.Height = OfficeColorPicker.PreferredHeight; _contextForm.Show(this, startLocation, OfficeColorPicker.PreferredWidth); }
public void Should_BePossibleTo_RightClick() { var contextMenuForm = new ContextMenuForm(); contextMenuForm.Open(); contextMenuForm.HotSpotLabel.MouseActions.RightClick(); Assert.DoesNotThrow(() => AqualityServices.Browser.HandleAlert(AlertAction.Decline), "Alert should be opened after right click"); }
/// <summary> /// Opens the control inside a context menu in the specified location /// </summary> /// <param name="startLocation">Screen coordinates location of the control</param> /// <param name="parent">Parent control to place the control at</param> public void Show(Control parent, Point startLocation) { _parentControl = parent; // Creates new contextmenu form, adds the control to it, display it. ContextMenuForm frm = new ContextMenuForm(); frm.SetContainingControl(this); frm.Height = OfficeColorPicker.PreferredHeight; _contextForm = frm; frm.Show(parent, startLocation, OfficeColorPicker.PreferredWidth); }
public static void Show(DataTable dataTable, string displayName, Control parent, Point point, Size size, EventHandler eventHandle, bool multiSelect, bool autoCalPoint, DataGridViewCellPaintingEventHandler cellPaintingEventHandle) { if (dataTable == null) { return; } _filtString = ""; _point = point; ContextMenuForm contextMenuForm = new ContextMenuForm(); contextMenuForm.ShowInTaskbar = false; ShowDevGridView(dataTable, displayName, parent, point, size, eventHandle, multiSelect, autoCalPoint, cellPaintingEventHandle, contextMenuForm); }
/// <summary> /// 弹出选择列表窗体 /// </summary> /// <param name="list">数据列表</param> /// <param name="displayName">需要显示的字段</param> /// <param name="parent">调用的控件</param> /// <param name="point">显示坐标</param> /// <param name="size">显示大小</param> /// <param name="eventHandle"></param> public static void Show(IEnumerable list, string displayName, Control parent, Point point, Size size, EventHandler eventHandle, ListType listType, bool multiSelect, bool autoCalPoint, DataGridViewCellPaintingEventHandler cellPaintingEventHandle) { if (list == null) { return; } IEnumerator en = list.GetEnumerator(); if (!en.MoveNext()) { return; } if (en.Current == null) { return; } _list = list; _filtString = ""; _point = point; ContextMenuForm contextMenuForm = new ContextMenuForm(); contextMenuForm.ShowInTaskbar = false; switch (listType) { case ListType.ListBox: ListBox lst = new ListBox(); lst.Font = new Font("宋体", 12); // 20); foreach (object obj in list) { Type type = obj.GetType(); string displayText = ""; try { displayText = type.GetProperty(displayName).GetValue(obj, null).ToString(); } catch { displayText = obj.ToString(); } lst.Items.Add(displayText); } lst.SelectedIndexChanged += new EventHandler(delegate(object sender1, EventArgs e1) { if (eventHandle != null) { eventHandle(lst.SelectedIndex, null); } contextMenuForm.Close(); }); contextMenuForm.Show(parent, point, size, lst); break; case ListType.ListView: ListView listView = new ListView(); listView.Font = new Font("宋体", 12); // 20); listView.View = View.List; listView.Columns.Add("选项"); listView.FullRowSelect = true; listView.HoverSelection = true; listView.LabelEdit = false; listView.HeaderStyle = ColumnHeaderStyle.None; listView.Resize += new EventHandler(delegate(object sender1, EventArgs e1) { listView.Columns[0].Width = listView.Width - 5; }); listView.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); foreach (object obj in list) { Type type = obj.GetType(); string displayText = ""; try { displayText = type.GetProperty(displayName).GetValue(obj, null).ToString(); } catch { displayText = obj.ToString(); } listView.Items.Add(displayText); } listView.KeyDown += new KeyEventHandler(delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (listView.SelectedIndices != null && listView.SelectedIndices.Count > 0) { if (eventHandle != null) { eventHandle(listView.SelectedIndices[0], null); } contextMenuForm.Close(); } } }); listView.Click += new EventHandler(delegate(object sender1, EventArgs e1) { if (listView.SelectedIndices != null && listView.SelectedIndices.Count > 0) { if (eventHandle != null) { eventHandle(listView.SelectedIndices[0], null); } contextMenuForm.Close(); } }); contextMenuForm.Show(parent, point, size, listView); break; case ListType.DataGridView: ShowDataGridView(list, displayName, parent, point, size, eventHandle, multiSelect, autoCalPoint, cellPaintingEventHandle, contextMenuForm); break; case ListType.PopupMenu: if (list != null) { ContextMenuStrip popupMenu = new ContextMenuStrip(); popupMenu.KeyDown += new KeyEventHandler(popupMenu_KeyDown); popupMenu.KeyPress += new KeyPressEventHandler(popupMenu_KeyPress); //popupMenu.Font = new Font("宋体", 12);// 21.75f); foreach (object obj in list) { Type type = obj.GetType(); string displayText = ""; try { displayText = type.GetProperty(displayName).GetValue(obj, null).ToString(); } catch { displayText = obj.ToString(); } ToolStripItem item = popupMenu.Items.Add(displayText); item.Click += new EventHandler(delegate(object sender1, EventArgs e1) { if (eventHandle != null) { eventHandle(popupMenu.Items.IndexOf(item), null); } }); } _point = parent.PointToScreen(point); popupMenu.Show(parent, point); } break; } }
private static void ShowDevGridView(DataTable dataTable, string displayName, Control parent, Point point, Size size, EventHandler eventHandle, bool multiSelect, bool autoCalPoint, DataGridViewCellPaintingEventHandler cellPaintingEventHandle, ContextMenuForm contextMenuForm) { _callControl = parent; DevExpress.XtraGrid.GridControl gridControl = new DevExpress.XtraGrid.GridControl(); DevExpress.XtraGrid.Views.Grid.GridView dataGridView = new DevExpress.XtraGrid.Views.Grid.GridView(); gridControl.MainView = dataGridView; dataGridView.OptionsView.ShowColumnHeaders = false; dataGridView.OptionsView.ShowGroupPanel = false; dataGridView.OptionsView.ShowIndicator = false; //dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //dataGridView.ColumnHeadersHeight = 18; //dataGridView.BackgroundColor = dataGridView.DefaultCellStyle.BackColor; //dataGridView.CellPainting += cellPaintingEventHandle; //dataGridView.CellPainting += new DataGridViewCellPaintingEventHandler(dataGridView_CellPainting); //dataGridView.GridColor = dataGridView.BackgroundColor; dataGridView.KeyPress += new KeyPressEventHandler(dataGridView_KeyPress); dataGridView.OptionsBehavior.ReadOnly = true; dataGridView.Tag = eventHandle; //DevExpress.XtraGrid.Columns.GridColumn column = dataGridView.Columns.Add(); //column.FieldName = //"字典选择器", "字典选择器"); //dataGridView.AllowUserToResizeRows = false; //dataGridView.AllowUserToResizeColumns = false; //dataGridView.ScrollBars = ScrollBars.Vertical; //dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; //dataGridView.Cursor = Cursors.Hand; string[] displayNames = null; string ddd = displayName; if (displayName != null) { displayNames = displayName.Split(new char[] { ',', ';' }); for (int i = 0; i < displayNames.Length; i++) { DevExpress.XtraGrid.Columns.GridColumn column = dataGridView.Columns.Add(); column.FieldName = displayNames[i]; column.OptionsColumn.AllowEdit = false; column.OptionsFilter.AllowAutoFilter = false; column.OptionsFilter.AllowFilter = false; column.Visible = true; column.VisibleIndex = 0; if (i == 0) { ddd = displayNames[i]; } } } _displayNames = displayNames; SetDataGridViewList(dataGridView, TransTable(dataTable, ddd)); //dataGridView.Resize += new EventHandler(delegate(object sender1, EventArgs e1) //{ // for (int i = 0; i < dataGridView.Columns.Count - 1; i++) // { // dataGridView.Columns[i].Width = 120; // } // int width = dataGridView.Width - 120 * (dataGridView.Columns.Count - 1); // if (width < 1) // { // dataGridView.Columns[dataGridView.Columns.Count - 1].Visible = false; // } // else // { // dataGridView.Columns[dataGridView.Columns.Count - 1].Width = width; // } //}); //dataGridView.CellDoubleClick += new DataGridViewCellEventHandler(delegate(object sender, DataGridViewCellEventArgs e) //{ // if (dataGridView.CurrentRow != null && dataGridView.CurrentRow.Index >= 0) // { // if (eventHandle != null) // { // if (multiSelect) // { // List<int> selectedIndexes = new List<int>(); // foreach (DataGridViewCell cell in dataGridView.SelectedCells) // { // selectedIndexes.Add(_showListItems[cell.RowIndex].Index); // } // selectedIndexes.Reverse(); // eventHandle(selectedIndexes.ToArray(), null); // if (dataGridView.Parent != null && dataGridView.Parent is DevExpress.XtraEditors.XtraForm) // { // (dataGridView.Parent as DevExpress.XtraEditors.XtraForm).Close(); // } // dataGridView.Dispose(); // } // } // } //}); dataGridView.KeyDown += new KeyEventHandler(dataGridView_KeyDown); if (!multiSelect) { //dataGridView.MouseMove += new MouseEventHandler(delegate(object sender, MouseEventArgs e) //{ // int rowIndex = dataGridView.get .HitTest(e.X, e.Y).RowIndex; // if (rowIndex >= 0) // { // dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[0]; // } //}); //dataGridView.CellClick += new DataGridViewCellEventHandler(delegate(object sender, DataGridViewCellEventArgs e) dataGridView.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(delegate(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) { if (eventHandle != null) { eventHandle(dataGridView.GetDataRow(e.RowHandle), e); } try { if (gridControl.Parent != null && gridControl.Parent is DevExpress.XtraEditors.XtraForm) { (gridControl.Parent as DevExpress.XtraEditors.XtraForm).Close(); } dataGridView.Dispose(); gridControl.Dispose(); } catch { } }); } if (size.Width < 100) { size.Width = 100; } //dataGridView.CellMouseDown += new DataGridViewCellMouseEventHandler(dataGridView_CellMouseDown); //dataGridView.CellMouseMove += new DataGridViewCellMouseEventHandler(dataGridView_CellMouseMove); //dataGridView.CellMouseUp += new DataGridViewCellMouseEventHandler(dataGridView_CellMouseUp); DevExpress.XtraEditors.XtraForm form = new DevExpress.XtraEditors.XtraForm(); form.TopMost = true; form.StartPosition = FormStartPosition.Manual; form.Location = parent.PointToScreen(point); form.Size = size; if (parent != null && !(parent is DataGridView)) { form.Width = parent.Width; } form.Controls.Add(gridControl); gridControl.Dock = DockStyle.Fill; form.Deactivate += new EventHandler(form_Deactivate); form.FormBorderStyle = FormBorderStyle.None; if (form.Bottom > Screen.PrimaryScreen.Bounds.Height) { if (form.Top >= form.Height) { form.Top -= form.Height; } else { form.Top = 0; } } form.Width = size.Width; form.Show(); }
private static void ShowDataGridView(IEnumerable list, string displayName, Control parent, Point point, Size size, EventHandler eventHandle, bool multiSelect, bool autoCalPoint, DataGridViewCellPaintingEventHandler cellPaintingEventHandle, ContextMenuForm contextMenuForm) { _callControl = parent; DataGridView dataGridView = new DataGridView(); dataGridView.ColumnHeadersVisible = false; dataGridView.RowHeadersVisible = false; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; dataGridView.ColumnHeadersHeight = 18; dataGridView.BackgroundColor = dataGridView.DefaultCellStyle.BackColor; dataGridView.CellPainting += cellPaintingEventHandle; dataGridView.CellPainting += new DataGridViewCellPaintingEventHandler(dataGridView_CellPainting); dataGridView.GridColor = dataGridView.BackgroundColor; dataGridView.KeyPress += new KeyPressEventHandler(dataGridView_KeyPress); dataGridView.ReadOnly = true; dataGridView.AllowUserToAddRows = false; dataGridView.AllowUserToDeleteRows = false; dataGridView.Columns.Add("字典选择器", "字典选择器"); dataGridView.AllowUserToResizeRows = false; dataGridView.AllowUserToResizeColumns = false; dataGridView.ScrollBars = ScrollBars.Vertical; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.Cursor = Cursors.Hand; string[] displayNames = null; if (displayName != null) { displayNames = displayName.Split(new char[] { ',', ';' }); for (int i = 1; i < displayNames.Length; i++) { dataGridView.Columns.Add("Column" + i.ToString(), "Column"); } if (dataGridView.Columns.Count > 1) { dataGridView.ScrollBars = ScrollBars.Both; } } _displayNames = displayNames; GenListItems(); SetDataGridViewList(dataGridView); dataGridView.Resize += new EventHandler(delegate(object sender1, EventArgs e1) { for (int i = 0; i < dataGridView.Columns.Count - 1; i++) { //dataGridView.Columns[i].Width = 120; dataGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; } //Modify by wenpei.x@2014-02-12 //新增人员选择下拉框显示User_ID,故宽度不应该再有限制 if (dataGridView.Columns.Count <= 1) { int width = dataGridView.Width - 120 * (dataGridView.Columns.Count - 1); if (width < 1) { dataGridView.Columns[dataGridView.Columns.Count - 1].Visible = false; } else { dataGridView.Columns[dataGridView.Columns.Count - 1].Width = width; } } }); dataGridView.CellDoubleClick += new DataGridViewCellEventHandler(delegate(object sender, DataGridViewCellEventArgs e) { if (dataGridView.CurrentRow != null && dataGridView.CurrentRow.Index >= 0) { if (eventHandle != null) { if (multiSelect) { List <int> selectedIndexes = new List <int>(); foreach (DataGridViewCell cell in dataGridView.SelectedCells) { selectedIndexes.Add(_showListItems[cell.RowIndex].Index); } selectedIndexes.Reverse(); eventHandle(selectedIndexes.ToArray(), null); if (dataGridView.Parent != null && dataGridView.Parent is DevExpress.XtraEditors.XtraForm) { (dataGridView.Parent as DevExpress.XtraEditors.XtraForm).Close(); } dataGridView.Dispose(); } } } }); dataGridView.KeyDown += new KeyEventHandler(delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (dataGridView.CurrentRow != null && dataGridView.CurrentRow.Index >= 0) { if (eventHandle != null) { if (multiSelect) { List <int> selectedIndexes = new List <int>(); foreach (DataGridViewCell cell in dataGridView.SelectedCells) { selectedIndexes.Add(_showListItems[cell.RowIndex].Index); } selectedIndexes.Reverse(); eventHandle(selectedIndexes.ToArray(), null); } else { eventHandle(_showListItems[dataGridView.CurrentRow.Index].Index, null); } } if (dataGridView.Parent != null && dataGridView.Parent is DevExpress.XtraEditors.XtraForm) { (dataGridView.Parent as DevExpress.XtraEditors.XtraForm).Close(); } dataGridView.Dispose(); } } else if (e.KeyCode == Keys.Escape) { if (dataGridView.Parent != null && dataGridView.Parent is DevExpress.XtraEditors.XtraForm) { (dataGridView.Parent as DevExpress.XtraEditors.XtraForm).Close(); } dataGridView.Dispose(); if (_callControl != null) { _callControl.Focus(); } } }); if (!multiSelect) { dataGridView.MouseMove += new MouseEventHandler(delegate(object sender, MouseEventArgs e) { int rowIndex = dataGridView.HitTest(e.X, e.Y).RowIndex; if (rowIndex >= 0) { dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[0]; } }); dataGridView.CellClick += new DataGridViewCellEventHandler(delegate(object sender, DataGridViewCellEventArgs e) { if (dataGridView.CurrentRow != null && dataGridView.CurrentRow.Index >= 0) { if (eventHandle != null) { eventHandle(_showListItems[dataGridView.CurrentRow.Index].Index, null); } try { if (dataGridView.Parent != null && dataGridView.Parent is DevExpress.XtraEditors.XtraForm) { (dataGridView.Parent as DevExpress.XtraEditors.XtraForm).Close(); } dataGridView.Dispose(); } catch { } } }); } if (size.Width < 100) { size.Width = 100; } dataGridView.CellMouseDown += new DataGridViewCellMouseEventHandler(dataGridView_CellMouseDown); dataGridView.CellMouseMove += new DataGridViewCellMouseEventHandler(dataGridView_CellMouseMove); dataGridView.CellMouseUp += new DataGridViewCellMouseEventHandler(dataGridView_CellMouseUp); DevExpress.XtraEditors.XtraForm form = new DevExpress.XtraEditors.XtraForm(); form.TopMost = true; form.StartPosition = FormStartPosition.Manual; form.Location = parent.PointToScreen(point); form.Size = size; //if (parent != null && !(parent is DataGridView)) //{ // form.Width = parent.Width; //} form.Controls.Add(dataGridView); dataGridView.Dock = DockStyle.Fill; form.Deactivate += new EventHandler(form_Deactivate); form.FormBorderStyle = FormBorderStyle.None; if (form.Bottom > Screen.PrimaryScreen.Bounds.Height) { if (form.Top >= form.Height) { form.Top -= form.Height; } else { form.Top = 0; } } form.Show(); //if (size.Height > dataGridView.RowTemplate.Height * dataGridView.Rows.Count + dataGridView.ColumnHeadersHeight) //{ // dataGridView.ColumnHeadersVisible = false; // Control parentControl = parent; // Dialog.SetPopup(dataGridView, parent, point, new Size(size.Width, dataGridView.RowTemplate.Height * dataGridView.Rows.Count + 3), autoCalPoint); //} //else //{ // Control parentControl = parent; // Dialog.SetPopup(dataGridView, parent, point, size, autoCalPoint); //} }