public Rectangle RangeToVisibleRectangle(Range range) { if (range.IsEmpty()) { return(Rectangle.Empty); } if (range.Start.Column < 0) { throw new ArgumentOutOfRangeException(string.Format("range.Start.Column was less than zero: {0}", range.Start.Column)); } if (range.Start.Row < 0) { throw new ArgumentOutOfRangeException(string.Format("range.Start.Row was less than zero: {0}", range.Start.Row)); } int firstRow = FindFirstVisibleRowFromRange(range); if (firstRow < 0) { return(Rectangle.Empty); } int actualFixedRows = m_Grid.ActualFixedRows; int actualFixedColumns = m_Grid.ActualFixedColumns; int y = m_Grid.Rows.GetTop(firstRow); if (m_Grid.IsRowHiddenUnderFixedRows(firstRow, true)) { y = m_Grid.GetFixedAreaHeight(); } int firstColumn = FindFirstVisibleColumnFromRange(range); if (firstColumn < 0) { return(Rectangle.Empty); } int x = m_Grid.Columns.GetLeft(firstColumn); if (IsColumnHiddenUnderFixedColumn(firstColumn, true)) { x = m_Grid.GetFixedAreaWidth(); } int lastColumn = range.End.Column; if (range.End.Column != actualFixedColumns - 1 && m_Grid.IsColumnHiddenUnderFixedColumn(range.End.Column)) { lastColumn = actualFixedColumns - 1; } int width = m_Grid.Columns.GetRight(lastColumn) - x; int lastRow = range.End.Row; if (range.End.Row != actualFixedRows - 1 && m_Grid.IsRowHiddenUnderFixedRows(range.End.Row)) { lastRow = actualFixedRows - 1; } int height = m_Grid.Rows.GetBottom(lastRow) - y; Size size = new Size(width, height); if (size.IsEmpty) { return(Rectangle.Empty); } return(new Rectangle(new Point(x, y), size)); }