Beispiel #1
0
 protected override void OnMouseClick(MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         var hit = HitTest(e.X, e.Y);
         if (hit != null && hit.Type == DataGridViewHitTestType.Cell)
         {
             ClearSelection();
             Rows[hit.RowIndex].Cells[hit.ColumnIndex].Selected = true;
             base.OnMouseClick(e);
             ShowContextMenu?.Invoke(this, new ContextMenuEventArgs(e.X, e.Y));
             return;
         }
     }
     base.OnMouseClick(e);
 }
Beispiel #2
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x007B)
            {
                if (ShowContextMenu != null)
                {
                    Point location = m.LParam.ToPoint();
                    if (location.X == -1 && location.Y == -1)
                    {
                        var pos = Caret.ScreenPosition;
                        ShowContextMenu?.Invoke(this, new MouseEventArgs(MouseButtons.None, clicks: 0, pos.X, pos.Y + TextArea.TextView.FontHeight, delta: 0));
                    }
                    else
                    {
                        var pos = PointToClient(location);
                        ShowContextMenu?.Invoke(this, new MouseEventArgs(MouseButtons.Right, clicks: 1, pos.X, pos.Y, delta: 0));
                    }
                }
            }

            base.WndProc(ref m);
        }