forked from sq/NDexer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchResultListBox.cs
63 lines (49 loc) · 2.03 KB
/
SearchResultListBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace Ndexer {
public class SearchResultListBox : ListBox {
Bitmap _ScratchBuffer = null;
Graphics _ScratchGraphics = null;
public SearchResultListBox()
: base() {
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
}
protected override void Dispose (bool disposing) {
DisposeGraphics();
base.Dispose(disposing);
}
void DisposeGraphics () {
if (_ScratchGraphics != null) {
_ScratchGraphics.Dispose();
_ScratchGraphics = null;
}
if (_ScratchBuffer != null) {
_ScratchBuffer.Dispose();
_ScratchBuffer = null;
}
}
protected Graphics GetScratchGraphics (Rectangle bounds) {
if ((_ScratchBuffer == null) || (_ScratchBuffer.Width < bounds.Width) || (_ScratchBuffer.Height < bounds.Height)) {
DisposeGraphics();
_ScratchBuffer = new Bitmap(bounds.Width, bounds.Height);
_ScratchGraphics = Graphics.FromImage(_ScratchBuffer);
}
_ScratchGraphics.SetClip(bounds, System.Drawing.Drawing2D.CombineMode.Replace);
return _ScratchGraphics;
}
protected override void OnDrawItem (DrawItemEventArgs e) {
var bounds = new Rectangle(0, 0, e.Bounds.Width, e.Bounds.Height);
var g = GetScratchGraphics(bounds);
g.Clear(e.BackColor);
var newArgs = new DrawItemEventArgs(g, e.Font, bounds, e.Index, e.State, e.ForeColor, e.BackColor);
base.OnDrawItem(newArgs);
e.Graphics.DrawImageUnscaledAndClipped(_ScratchBuffer, e.Bounds);
}
protected override void OnPaintBackground (PaintEventArgs pevent) {
}
}
}