C#
C# -- listview, panel 에서 double buffered, ResizeRedraw Extension 사용하기
자유프로그램
2015. 12. 12. 02:26
반응형
C# -- listview, panel 에서 double buffered, ResizeRedraw Extension 사용하기
참고 : http://stackoverflow.com/a/15268338
http://stackoverflow.com/a/29438857
http://www.codeproject.com/Articles/3567/Flicker-free-ListView-in-NET-and-XP
답변 ;
버퍼를 2개 만들어 한꺼번에 Switch하는 방식으로 더블버퍼링을 사용하면 Flicker현상을 막을 수 있습니다.이를 위해 DoubleBuffered 라는 속성을 true로 설정하면 되는데, 이 속성이 protected라서 아래와 같이 Reflection을 사용하는 확장메서드를 작성한 후,
public static class Extensions {
public static void DoubleBuffered(this Control control, bool enabled)
{
var prop = control.GetType().GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
prop.SetValue(control, enabled, null);
}
}
리스트뷰에서 속성을 아래와 같이 지정합니다
listView1.DoubleBuffered(true);
--
< 소스 >
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Reflection; // 반드시 필요함. | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
this.SetStyle(ControlStyles.ResizeRedraw, true); | |
this.listView1.DoubleBuffered(true); // DoubleBuffered Extension 사용 | |
this.drawingPanel.ResizeRedraw(true); // ResizeRedraw Extension 사용 | |
} | |
} | |
public static class Extensions | |
{ | |
public static void ResizeRedraw(this Control control, bool enabled) | |
{ | |
var prop = control.GetType().GetProperty("ResizeRedraw", BindingFlags.Instance | BindingFlags.NonPublic); | |
prop.SetValue(control, enabled, null); | |
} | |
public static void DoubleBuffered(this Control control, bool enabled) | |
{ | |
var prop = control.GetType().GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic); | |
prop.SetValue(control, enabled, null); | |
} | |
} |
반응형