내 소유자가 그려진 목록 상자에도 비슷한 문제가있었습니다. 내 솔루션은 BufferedGraphics 개체를 사용하는 것이 었습니다. 주인이 그려,하지만 어쩌면 그것은 당신에게 영감을 줄 것이다. 내가있는 TextRenderer 내가 TextFormatFlags.Prese을 suppled하지 않는 한 올바른 위치로 렌더링 어려움을 남겼
rveGraphicsTranslateTransform. 대신 P/Invoke를 사용하여 BitBlt를 호출하여 그래픽 컨텍스트간에 픽셀을 직접 복사 할 수있었습니다. 나는 이것을 두 가지 악의 적은 것으로 선택했다.
/// <summary>
/// This class is a double-buffered ListBox for owner drawing.
/// The double-buffering is accomplished by creating a custom,
/// off-screen buffer during painting.
/// </summary>
public sealed class DoubleBufferedListBox : ListBox
{
#region Method Overrides
/// <summary>
/// Override OnTemplateListDrawItem to supply an off-screen buffer to event
/// handlers.
/// </summary>
protected override void OnDrawItem(DrawItemEventArgs e)
{
BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
Rectangle newBounds = new Rectangle(0, 0, e.Bounds.Width, e.Bounds.Height);
using (BufferedGraphics bufferedGraphics = currentContext.Allocate(e.Graphics, newBounds))
{
DrawItemEventArgs newArgs = new DrawItemEventArgs(
bufferedGraphics.Graphics, e.Font, newBounds, e.Index, e.State, e.ForeColor, e.BackColor);
// Supply the real OnTemplateListDrawItem with the off-screen graphics context
base.OnDrawItem(newArgs);
// Wrapper around BitBlt
GDI.CopyGraphics(e.Graphics, e.Bounds, bufferedGraphics.Graphics, new Point(0, 0));
}
}
#endregion
}
난 그냥이 구현 그것은 완벽하게 작동합니다. – test
@ 에릭 : 어디서 GDI를 구합니까? 그것은 레퍼런스인가? 예를 들어'Graphics GDI = this.CreateGraphics(); '를 추가하려했지만 CopyGraphics 메서드가 없습니다. 또는 이전에 Gdi32.dll을 가져 왔습니까? – Matt
알았어 - 지금 일해. 나는'GDI32.dll'을'BitBlt' 메서드와 함께 추가하고'GDI.CopyGraphics (...) '로 감싸고 이제는 작동합니다 ... 유일하게 원래 ListBox와 똑같이 깜박입니다. 어떤 아이디어로 그것을 고치는 법? – Matt