//protected override void OnEnter(int rowIndex, bool throughMouseClick) //{ // base.OnEnter(rowIndex, throughMouseClick); // if (this.Selected && string.IsNullOrEmpty(Convert.ToString(this.Value))) // { // if (this.DataGridView.BeginEdit(true)) // { // var popup = Popup; // popup.Selected += PopupControl_Selected; // PopupForm.Show(txtPopup, popup, this.PopupWidth, popup.Height); // } // } //} protected override void OnClick(DataGridViewCellEventArgs e) { var popup = Popup; popup.DataBind(); popup.Selected += PopupControl_Selected; int cellX = DataGridView.GetCellDisplayRectangle(ColumnIndex, RowIndex, false).X; int cellY = DataGridView.GetCellDisplayRectangle(ColumnIndex, RowIndex, false).Y; Point pi = new Point(cellX, cellY + this.DataGridView.CurrentCell.OwningRow.Height); pi = DataGridView.PointToScreen(pi); if (pi.X + this.PopupWidth > Screen.PrimaryScreen.WorkingArea.Width) { pi.X = Screen.PrimaryScreen.WorkingArea.Width - this.PopupWidth; } if (pi.Y + popup.Height > Screen.PrimaryScreen.WorkingArea.Height) { pi.Y = pi.Y - this.DataGridView.CurrentCell.OwningRow.Height - popup.Height; } PopupForm.Show(pi, popup, this.PopupWidth, popup.Height); }
protected override void OnEnter(EventArgs e) { base.OnEnter(e); if (this.Focused && string.IsNullOrEmpty(Convert.ToString(this.Value)) && PopupDataSource != null) { var popup = Popup; popup.DataBind(); popup.Selected += PopupControl_Selected; PopupForm.Show(this, popup, this.PopupWidth, popup.Height); } }
protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.Enter && PopupDataSource != null) { e.Handled = true; var popup = Popup; popup.DataBind(); popup.Selected += PopupControl_Selected; PopupForm.Show(this, popup, this.PopupWidth, popup.Height); } else { base.OnKeyDown(e); } }
public static void Show(Point location, Control popupCtrl, int width, int height) { PopupForm popupFrm = new PopupForm(); popupFrm.Location = location; popupFrm.Controls.Clear(); popupFrm.Controls.Add(popupCtrl); popupCtrl.Dock = DockStyle.Fill; popupFrm.Width = width; popupFrm.Height = height + GetTop(popupCtrl) + GetBottom(popupCtrl); popupFrm.Show(); }
protected override void OnKeyDown(KeyEventArgs e, int rowIndex) { if (e.KeyCode == Keys.Enter) { e.Handled = true; //if (this.DataGridView.BeginEdit(true)) //{ var popup = Popup; popup.DataBind(); popup.Selected += PopupControl_Selected; //PopupForm.Show(txtPopup, popup, this.PopupWidth, popup.Height); int cellX = DataGridView.GetCellDisplayRectangle(ColumnIndex, RowIndex, false).X; int cellY = DataGridView.GetCellDisplayRectangle(ColumnIndex, RowIndex, false).Y; Point pi = new Point(cellX, cellY + this.DataGridView.CurrentCell.OwningRow.Height); pi = DataGridView.PointToScreen(pi); if (pi.X + this.PopupWidth > Screen.PrimaryScreen.WorkingArea.Width) { pi.X = Screen.PrimaryScreen.WorkingArea.Width - this.PopupWidth; } if (pi.Y + popup.Height > Screen.PrimaryScreen.WorkingArea.Height) { pi.Y = pi.Y - this.DataGridView.CurrentCell.OwningRow.Height - popup.Height; } PopupForm.Show(pi, popup, this.PopupWidth, popup.Height); //} } else if (e.KeyCode == Keys.Back) //删除键 { this.Value = ""; } else { base.OnKeyDown(e, rowIndex); } }