Exemplo n.º 1
0
 private bool RemoveRangeRecursive(GridRange rangeToRemove)
 {
     rangeToRemove = NormalizeRange(rangeToRemove);
     for (int i = 0; i < m_ranges.Count; i++)
     {
         GridRange range = m_ranges[i];
         if (range.IntersectsWith(rangeToRemove) == false)
         {
             continue;
         }
         GridRange intersection = range.Intersect(rangeToRemove);
         m_ranges.Remove(range);
         RangeRegion excludedRanges = range.Exclude(intersection);
         InternalAdd(excludedRanges);
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
        public override void Draw(RangePaintEventArgs e)
        {
            RangeRegion region = mSelection.GetSelectionRegion();

            if (region.IsEmpty())
            {
                return;
            }

            // get visible range for scrollable area
            GridRange visibleScrollabeRange = mSelection.Grid.RangeAtAreaExpanded(CellPositionType.Scrollable);


            System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor);

            CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition);
            // get focus rectangle
            // clipped to visible range
            GridRange focusClippedRange = visibleScrollabeRange.Intersect(new GridRange(mSelection.ActivePosition, mSelection.ActivePosition));

            System.Drawing.Rectangle focusRect = e.Grid.PositionToRectangle(focusClippedRange.Start);

            //Draw each selection range
            foreach (GridRange rangeToLoop in region)
            {
                // intersect given range with visible range
                // this way we ensure we don't loop through thousands
                // of rows to calculate rectToDraw
                GridRange rng = visibleScrollabeRange.Intersect(rangeToLoop);


                System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng);
                if (rectToDraw == System.Drawing.Rectangle.Empty)
                {
                    continue;
                }

                System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw);

                if (rectToDraw.IntersectsWith(focusRect))
                {
                    regionToDraw.Exclude(focusRect);
                }

                e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw);

                //Draw the border only if there isn't a editing cell
                // and is the range that contains the focus or there is a single range
                if (rng.Contains(mSelection.ActivePosition) || region.Count == 1)
                {
                    if (focusContext.IsEditing() == false)
                    {
                        mSelection.Border.Draw(e.GraphicsCache, rectToDraw);
                    }
                }
            }

            //Draw Focus
            System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor);
            e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect);
        }