Ejemplo n.º 1
0
        protected override void OnMouseMove(GLMouseEventArgs e)
        {
            base.OnMouseMove(e);

            GLDataGridView dgv = Parent as GLDataGridView;

            int xoff = e.Location.X + HorzScroll;

            if (dragging == 0)
            {
                dgv.RowHeaderWidth = xoff + initialrowheaderwidth;
            }
            else if (dragging == -2)
            {
                dgv.ColumnHeaderHeight = e.Location.Y;
            }
            else if (dragging > 0)
            {
                int colx = xoff - dgv.ColumnPixelLeft(dragging - 1);
                dgv.SetColumnWidth(dragging - 1, colx);
            }
            else
            {
                var over = Over(e.Location);
                Cursor = (over != null && over.Item1 == ClickOn.Divider) ? GLWindowControl.GLCursorType.EW :
                         (over != null && over.Item1 == ClickOn.Height) ? GLWindowControl.GLCursorType.NS :
                         GLWindowControl.GLCursorType.Normal;
            }
            return;
        }
        // returns real row number
        public GLDataGridView.RowColPos GridRowCol(Point p)
        {
            if (gridrowoffsets.Count > 0)
            {
                int y = ScrollOffset.Y + Math.Max(0, Math.Min(p.Y, ClientHeight));      // if mouse if captured, y may be well beyond grid, clip to it

                int gridrow = gridrowoffsets.FindLastIndex(a => a < y);

                if (gridrow >= 0 && gridrow < gridrowoffsets.Count - 1)        // last entry is end of grid, either reject or accept
                {
                    GLDataGridView dgv = Parent as GLDataGridView;

                    int xoffset = ScrollOffset.X + Math.Max(0, Math.Min(p.X, ClientWidth));     // clip X

                    for (int i = 0; i < dgv.Columns.Count; i++)
                    {
                        int left = dgv.ColumnPixelLeft(i);
                        if (xoffset >= left && xoffset < left + dgv.Columns[i].Width)
                        {
                            Point off     = new Point(xoffset - left, y - gridrowoffsets[gridrow]);
                            Point cellloc = new Point(left, gridrowoffsets[gridrow] + dgv.CellBorderWidth);
                            gridrow += gridfirstline;
                            return(new GLDataGridView.RowColPos()
                            {
                                Row = gridrow, Column = i, Location = off, CellLocation = cellloc
                            });
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        private Tuple <ClickOn, int, Point> Over(Point p)
        {
            GLDataGridView dgv  = Parent as GLDataGridView;
            int            xoff = p.X + HorzScroll;

            if (dgv.AllowUserToResizeColumns)
            {
                foreach (var c in dgv.Columns)  // horz part, col headers
                {
                    int hoff = xoff - dgv.ColumnPixelLeft(c.Index);

                    // System.Diagnostics.Debug.WriteLine($"loc {p} col {c.Index} {c.HeaderBounds} {hoff}");
                    if (hoff >= leftmargin && hoff <= rightmargin)
                    {
                        // System.Diagnostics.Debug.WriteLine($"Header mouse over divider {c.Index} {p}");
                        return(new Tuple <ClickOn, int, Point>(ClickOn.Divider, c.Index, Point.Empty));
                    }
                }

                if (dgv.Columns.Count > 0 && dgv.ColumnFillMode != GLDataGridView.ColFillMode.FillWidth)
                {
                    int hoff = xoff - dgv.ColumnPixelRight(dgv.Columns.Count - 1);
                    if (hoff >= leftmargin && hoff <= rightmargin)
                    {
                        return(new Tuple <ClickOn, int, Point>(ClickOn.Divider, dgv.Columns.Count, new Point(hoff, p.Y)));
                    }
                }
            }

            if (p.Y >= Height - bottommargin && dgv.AllowUserToResizeColumnHeight)
            {
                return(new Tuple <ClickOn, int, Point>(ClickOn.Height, -1, Point.Empty));
            }

            foreach (var c in dgv.Columns)  // horz part, col headers
            {
                int left = dgv.ColumnPixelLeft(c.Index);
                if (xoff > left && xoff < left + c.Width)
                {
                    // System.Diagnostics.Debug.WriteLine($"Header mouse over {c.Index} {p}");
                    return(new Tuple <ClickOn, int, Point>(ClickOn.Header, c.Index, new Point(xoff - left, p.Y)));
                }
            }

            return(null);
        }