2014-03-04 3 views
1

DGV에서 선택한 셀 주위에 직사각형을 그리는 함수를 구현하고 있습니다. 이 함수는 각 SelectionChanged 이벤트에서 발생하고 SelectedCells에서 두 개의 대각선 셀을 찾고 그 사이에 Rectangle을 그립니다.DataGridView GetCellDisplayRectangle too slow

그러나 방법 GetCellDisplayRectangle(index,index,bool);은 실제로 느리다. ~ 1300ticks이고, 나는 그것을 두 번 호출한다. 결과적으로 Rectangle의 선택 영역이 너무 느리고 렌더러가 부드럽게 보이지 않습니다.

내 질문은 DGV에서 특정 셀의 X, Y, 높이, 너비를 찾는 방법이 있습니까?

는 WH

답변

2
private Rectangle GetCellRectangle(int columnIndex, int rowIndex) 
     { 
      Rectangle selRect = new Rectangle(0, 0, 0, 0); 

      selRect.X = RowHeadersWidth + 1; 
      for (int i = FirstDisplayedScrollingColumnIndex; i < columnIndex; i++) 
      { 
       selRect.X += Columns[i].Width; 
      } 
      selRect.X -= FirstDisplayedScrollingColumnHiddenWidth; 

      selRect.Y = ColumnHeadersHeight + 1; 
      for (int i = FirstDisplayedScrollingRowIndex; i < rowIndex; i++) 
      { 
       selRect.Y += Rows[i].Height; 
      } 

      selRect.Width = Rows[rowIndex].Cells[columnIndex].Size.Width; 
      selRect.Height = Rows[rowIndex].Cells[columnIndex].Size.Height; 
      return selRect; 
     } 

이 메소드는 반환 CellDisplayRectangle에게 인 (1300)

0

당신은 이러한 폭과 INT의 높이를 반환

cell.ContentBound.Width /*and */ cell.ContentBound.Height 

사용하여 높이와 셀의 폭을 얻을 수 있습니다 감사합니다.

은 그렇지가, 함께 aprox 8-10 틱의 크기 속성

cell.Size.Width /*and */ cell.Size.Height 
+0

지금까지 최고의 아이디어의 insted! ty – Mastenka

+0

글쎄,이 방법은 현재 셀의 너비와 높이를 찾는 것이 가능하기 때문에 이것을 대답으로 표시 할 수는 없지만 셀의 X와 Y를 찾을 수는 없습니다. – Mastenka

+0

위치가 dgv입니까? –