Ejemplo n.º 1
0
        private void AddContextMenu()
        {
            var eventsController = new CustomEvents();
            var contextMenu      = new ContextMenuStrip();
            var customEvents     = new FrmSample21Events(this.grid1);

            contextMenu.Items.Add(customEvents.GetInsertRowItem());
            contextMenu.Items.Add(customEvents.GetRemoveRowItem());

            contextMenu.Items.Add(customEvents.GetInsertColItem());
            contextMenu.Items.Add(customEvents.GetRemoveColItem());

            eventsController.MouseDown += delegate(object sender, MouseEventArgs e)
            {
                if (e.Button != MouseButtons.Right)
                {
                    return;
                }
                var context = (CellContext)sender;
                grid1.Selection.Focus(context.Position, true);
                grid1.Selection.SelectCell(context.Position, true);
                var rect = grid1.RangeToRectangle(new Range(context.Position, context.Position));
                customEvents.LastPosition = context.Position;
                contextMenu.Show(grid1, rect.Location);
            };
            grid1.Controller.AddController(eventsController);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draw the highlighted cells.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="drawingRange">The range of cells that must be redrawed. Consider that can contains also not selected cells.</param>
        protected virtual void DrawHighlight(DevAge.Drawing.GraphicsCache graphics, Range drawingRange)
        {
            if (Region.IsEmpty() ||
                Region.IntersectsWith(drawingRange) == false)
            {
                return;
            }

            System.Drawing.Brush brush = graphics.BrushsCache.GetBrush(BackColor);

            foreach (Range rng in Region.GetRanges())
            {
                System.Drawing.Rectangle rectToDraw = Grid.RangeToRectangle(rng);
                if (rectToDraw == System.Drawing.Rectangle.Empty)
                {
                    continue;
                }

                System.Drawing.RectangleF contentRect = Border.GetContentRectangle(rectToDraw);

                graphics.Graphics.FillRectangle(brush, contentRect);

                Border.Draw(graphics, rectToDraw);
            }
        }
Ejemplo n.º 3
0
        public void PaintMergedCell(GraphicsCache graphics, Range cellRange, CellContext cellContext)
        {
            Grid grid = m_Grid as Grid;

            if (grid == null)
            {
                return;
            }

            Rectangle spanRect = grid.RangeToRectangle(cellRange);

            grid.PaintMergedCell(graphics, cellContext, spanRect);
        }
Ejemplo n.º 4
0
        public void PaintMergedCell(GraphicsCache graphics, Range cellRange, CellContext cellContext)
        {
            Grid grid = m_Grid as Grid;

            if (grid == null)
            {
                return;
            }

            GraphicsState state = graphics.Graphics.Save();

            graphics.Graphics.ResetClip();
            graphics.Graphics.ResetTransform();

            Rectangle spanRect = grid.RangeToRectangle(cellRange);

            Rectangle clientRectangle = grid.RangeToVisibleRectangle(cellRange);

            int actualFixedColumns = grid.ActualFixedColumns;
            int actualFixedRows    = grid.ActualFixedRows;

            if (cellRange.Start.Column < actualFixedColumns && cellRange.End.Column >= actualFixedColumns)
            {
                spanRect.Width = clientRectangle.Width;
            }

            if (cellRange.Start.Row < actualFixedRows && cellRange.End.Row >= actualFixedRows)
            {
                spanRect.Height = clientRectangle.Height;
            }


            graphics.Graphics.SetClip(clientRectangle);

            graphics.Graphics.TranslateTransform(spanRect.X - clientRectangle.X, spanRect.Y - clientRectangle.Y);

            spanRect.Location = clientRectangle.Location;

            using (GraphicsCache graphicsCache = new GraphicsCache(graphics.Graphics, Rectangle.Round(graphics.Graphics.ClipBounds)))
            {
                grid.PaintMergedCell(graphicsCache, cellContext, spanRect);
            }

            graphics.Graphics.ResetTransform();
            graphics.Graphics.ResetClip();
            graphics.Graphics.Restore(state);
        }
Ejemplo n.º 5
0
        public System.Drawing.Rectangle GetDrawingRectangle()
        {
            if (mRange.IsEmpty())
            {
                return(System.Drawing.Rectangle.Empty);
            }

            return(Grid.RangeToRectangle(mRange));

            ////Remove the not visible part
            //Range rngVisible = Grid.GetVisibleRange();
            //Range drawing = mRange.Intersect(rngVisible);

            //if (drawing.IsEmpty() == false)
            //{
            //    return Grid.RangeToRectangle(drawing);
            //}
            //else
            //    return System.Drawing.Rectangle.Empty;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Draw the selection using the SelectionColor property over the selected cells. Draw a Border around the selection using Border and BorderMode properties.
        /// </summary>
        /// <param name="p_Panel"></param>
        /// <param name="graphics"></param>
        /// <param name="pRangeToRedraw">The range of cells that must be redrawed. Consider that can contains also not selected cells.</param>
        public virtual void DrawSelectionMask(GridSubPanel p_Panel, DevAge.Drawing.GraphicsCache graphics, Range pRangeToRedraw)
        {
            if (IsEmpty())
            {
                return;
            }

            Region     oldClip       = graphics.Graphics.Clip;
            SolidBrush brushFillMask = graphics.BrushsCache.GetBrush(BackColor);

            try
            {
                graphics.Graphics.Clip = new Region(graphics.ClipRectangle);

                Range     rangeFocus = Range.Empty;
                Rectangle rectFocus  = Rectangle.Empty;
                if (m_ActivePosition.IsEmpty() == false && pRangeToRedraw.Contains(m_ActivePosition))
                {
                    rectFocus  = p_Panel.RectangleGridToPanel(Grid.PositionToRectangle(m_ActivePosition));
                    rangeFocus = Grid.PositionToCellRange(m_ActivePosition);
                }
                Cells.ICellVirtual cellFocus = Grid.GetCell(m_ActivePosition);

                //Draw selection mask and border
                //Draw each cell separately
                if ((m_MaskStyle & SelectionMaskStyle.DrawOnlyInitializedCells) == SelectionMaskStyle.DrawOnlyInitializedCells &&
                    (MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)                      //Draw Over cells enabled?
                {
                    PositionCollection selectedCells = GetCellsPositions();
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        //if must be redrawed, is is not the cell with the focus and contains a cell
                        if (pRangeToRedraw.Contains(selectedCells[i]) && rangeFocus.Contains(selectedCells[i]) == false &&
                            Grid.GetCell(selectedCells[i]) != null)
                        {
                            Rectangle rect = p_Panel.RectangleGridToPanel(Grid.PositionToRectangle(selectedCells[i]));
                            graphics.Graphics.FillRectangle(brushFillMask, rect);
                        }
                    }
                }
                //draw all the selected ranges (Default) //Draw Over cells enabled?
                else if ((MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)
                {
                    RangeCollection selectedRanges = GetRanges();
                    for (int i = 0; i < selectedRanges.Count; i++)
                    {
                        Range range = selectedRanges[i];
                        if (range.IntersectsWith(pRangeToRedraw))
                        {
                            Rectangle rect = p_Panel.RectangleGridToPanel(Grid.RangeToRectangle(range));

                            if (range.Contains(m_ActivePosition))
                            {
                                Region region = new Region(rect);
                                region.Exclude(rectFocus);
                                graphics.Graphics.FillRegion(brushFillMask, region);
                            }
                            else
                            {
                                graphics.Graphics.FillRectangle(brushFillMask, rect);
                            }
                        }
                    }
                }

                //Draw focus mask and focus border (only if there is a fucus cell and is not in editng mode)
                CellContext focusCellContext = new CellContext(Grid, m_ActivePosition, cellFocus);
                if (cellFocus != null && focusCellContext.IsEditing() == false &&
                    pRangeToRedraw.Contains(m_ActivePosition))
                {
                    //Draw Over cells enabled?
                    if ((MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)
                    {
                        if (m_FocusBackColor != Color.Transparent)
                        {
                            Brush focusBrush = graphics.BrushsCache.GetBrush(m_FocusBackColor);
                            graphics.Graphics.FillRectangle(focusBrush, rectFocus);
                        }
                    }
                }

                if (focusCellContext.IsEditing() == false)
                {
                    mRangeHighlight.DrawHighlight(p_Panel, graphics, pRangeToRedraw);
                }
            }
            finally
            {
                graphics.Graphics.Clip = oldClip;
            }
        }