2013-10-04 5 views
0

Windows Forms StatusBar 클래스에서 이중 버퍼링을 사용할 수 있습니까?Windows Forms 상태 표시 줄에서 더블 버퍼링을 활성화하려면 어떻게합니까?

마우스 이동 이벤트에서 일부지도 좌표를 업데이트 중이며 깜박 거리거나 다시 칠하는 것이 아주 분명합니다. StatusBar 클래스에서 상속 받고 해당 DoubleBuffer = true을 설정하고 OnPaintBackground 메서드를 재정의했습니다. 나도 행운을 빌리지 않고 주인을 그려 보았습니다.

+1

기본적으로 'DoubleBuffered = false'가 설정되어 있는데 왜 그렇게 설정합니까? 게다가 이중 버퍼를 사용하려면'false'가 아닌'true'로 설정해야합니다. –

+0

나는 확실히 '사실'을 의미했다. 결정된. – Brannon

+0

'StatusBar'에 무언가를 그립니다. 몇 가지 정보를 표시해야한다면'Label' 또는'Panel'을 커스터마이징 해보십시오. 너무 어렵지 않고 결코 깜박 거리지 않을 것입니다. –

답변

0

System.Windows.Forms.StatusBar은 레거시 컨트롤이므로 DoubleBuffered 속성에 대해 신경 쓸 필요가 없습니다. 당신은 파생 클래스의 생성자에서 지금처럼 설정을 시도 할 수 있습니다 :

this.SetStyle(ControlStyles.DoubleBuffer, true);

난 정말 StatusStrip 제어를 시도하는 것이 좋습니다 있지만. StatusBar은 Windows Forms 용이며 OS에 의해 그려지지 않습니다.

+0

StatusStrip (관리 렌더러 사용) 및 ToolStripStatusLabel (테두리가 에칭 됨)으로 변경되었으며 완벽하게 작동합니다. 고맙습니다. – Brannon

0
//declare a renderer, but do not initialize in here, 
//because if current theme is classics, it will error 
VisualStyleRenderer _barRenderer; 

protected override void WndProc(ref Message m) 
{ 
    switch (m.Msg) 
    { 
     //eat WM_ERASEBKGND, and in WM_PAINT draw the background 
     case 0x14: 
      m.Result = (IntPtr)1; 
      return; 

     case 0xF://WM_PAINT 
      PAINTSTRUCT ps; 
      var hdc = BeginPaint(m.HWnd, out ps); //see MSDN 
      BufferedGraphics bg = null; //use memory graphics 
      try 
      { 
       var rect = ClientRectangle; 
       bg = BufferedGraphicsManager.Current.Allocate(hdc, rect); 

       //draw background 
       if (Application.RenderWithVisualStyles) 
       { 
        //just initialize renderer once 
        if (_barRenderer == null) 
        { 
         _barRenderer = new VisualStyleRenderer(VisualStyleElement.Status.Bar.Normal); 
        } 
        _barRenderer.DrawBackground(bg.Graphics, rect); 
       } 
       else 
       { 
        bg.Graphics.SetClip(rect); //not essential 
        bg.Graphics.Clear(SystemColors.Control); 
       } 

       //let system draw foreground, include texts, icons, separators etc 
       m.WParam = bg.Graphics.GetHdc(); //required, GetHdc() is not only obtain a dc handle, 
       base.WndProc(ref m);    //it open a context for the dc, and let system draw on this context 
       bg.Graphics.ReleaseHdc();  //timely release 

       bg.Render(); 
       return; 
      } 
      finally 
      { 
       if (bg != null) { bg.Dispose(); } 
       EndPaint(m.HWnd, ref ps); //see MSDN 
      } 
    } 
    base.WndProc(ref m); 
} 

#region Win32 API 

[DllImport("user32.dll")] 
private static extern IntPtr BeginPaint(IntPtr hWnd, out PAINTSTRUCT lpPaint); 

[DllImport("user32.dll")] 
private static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT lpPaint); 

[StructLayout(LayoutKind.Sequential)] 
private struct PAINTSTRUCT 
{ 
    public IntPtr hdc; 
    public bool fErase; 
    public RECT rcPaint; 
    public bool fRestore; 
    public bool fIncUpdate; 
    public int reserved1; 
    public int reserved2; 
    public int reserved3; 
    public int reserved4; 
    public int reserved5; 
    public int reserved6; 
    public int reserved7; 
    public int reserved8; 
} 

[StructLayout(LayoutKind.Sequential)] 
private struct RECT 
{ 
    public int Left; 
    public int Top; 
    public int Right; 
    public int Bottom; 
} 

#endregion 
+0

꽤 많은 코드가 있습니다. 독자가 의도와 상황을 이해할 수 있도록 설명을 추가하거나 코드를 크게 언급하는 것을 고려하십시오. – ADyson

+0

@ADyson, 알았어.하지만 내 영어가 좋지 않아. 나는 그것을 시도 할 것이다. – ahdung