2009-02-25 5 views
5

윈도우 폼이 있습니다. 거기에 여러 개의 datagridview가 있습니다. 어떤 시점에서 사용자는 데이터 그 리드 뷰를 업데이트하는 버튼을 누를 수 있습니다. 그들이 할 때, 그들은 일반적으로 앉아서 datagridview 자체를 한 번에 한 행을 볼 수 있습니다. 나는 내가 SuspendLayout/ResumeLayout 기능을 본 적이Windows 다시 그리기 양식을 잠급니다.

Control.SuspendRedraw() 
this.doStuff() 
this.doOtherStuff() 
this.doSomeReallyCoolStuff() 
Control.ResumeRedaw() 

로 제어를 알 수있는 방법을 싶습니다, 즉, 그 "완료"가 나타날 때까지 페인트하지으로 제어하고 싶습니다,하지만 그들은 할 아무 것도 없습니다 (데이터 값을 편집하는 것뿐만 아니라 크기 조정/이동 컨트롤과 관련이있는 것 같습니다)

+0

가능한 중복이있을 것이다 WM_SETREDRAW는 Win32 메시지입니다 및 그 자녀?] (http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children) –

+0

참조 http://stackoverflow.com/ 질문/487661/how-do-i-suspend-painting-for-a-contro l-and-its-children – Simon

답변

8

당신이 시도 할 수 있습니다 몇 가지가 있습니다. 이 속성은 Form이 아닌 실제 DataGridView 인스턴스의 속성입니다. 보호 된 속성이므로 그리드를 하위 클래스로 설정해야합니다. 나는 작은 무승부 업데이트를 많이 본 적이

class CustomDataGridView: DataGridView 
{ 
    public CustomDataGridView() 
    { 
     DoubleBuffered = true; 
    } 
} 

는 일부 비디오 카드에 DataGridView에있는 시간이 걸릴, 이것은 그들이 디스플레이 퇴장하기 전에 그것들을 일괄 처리하여 문제를 해결할 수 있습니다.


당신이 시도 할 수있는 또 다른 점은 [어떻게 컨트롤에 대한 그림을 중단 할

다른 곳 코드에서
// ... this would be defined in some reasonable location ... 

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] 
static extern IntPtr SendMessage(HandleRef hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam); 

static void EnableRepaint(HandleRef handle, bool enable) 
{ 
    const int WM_SETREDRAW = 0x000B; 
    SendMessage(handle, WM_SETREDRAW, new IntPtr(enable ? 1 : 0), IntPtr.Zero); 
} 

당신의

HandleRef gh = new HandleRef(this.Grid, this.Grid.Handle); 
EnableRepaint(gh, false); 
try 
{ 
    this.doStuff(); 
    this.doOtherStuff(); 
    this.doSomeReallyCoolStuff(); 
} 
finally 
{ 
    EnableRepaint(gh, true); 
    this.Grid.Invalidate(); // we need at least one repaint to happen... 
} 
0

DoubleBuffer를 사용하도록 폼을 설정할 수 있습니다. Form.DoubleBuffer 속성을 true로 설정하면 문제가 해결됩니다. ,

먼저 true로 DataGridView에의에 Doublebuffer 속성을 설정하려고 :

+0

다시 그리기를 부드럽게 처리하지만 각 상자가 그려진 것을 계속 볼 수 있습니다. – GWLlosa