Skip to content

Instantly share code, notes, and snippets.

@hamxiaoz
Created February 16, 2016 18:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hamxiaoz/948797e2324c7ee23c16 to your computer and use it in GitHub Desktop.
Ultra fast real-time data display in ObjectListView
// Refresh the data in timer or in live data update callback
this.timer.Tick += (s, e) => {
// draw the live value
using (Graphics g = this.dataListView1.CreateGraphics())
{
// shrink the drawing area so that the grid line and selection color can be seen.
Rectangle r = lvi.GetSubItem(4).Bounds;
r.Inflate(-2, -2);
// use double buffer to avoid flicker
using (BufferedGraphics bg = BufferedGraphicsManager.Current.Allocate(g, r))
{
// clear the last graphics and draw
bg.Graphics.Clip = new Region(r);
bg.Graphics.Clear(this.dataListView1.BackColor);
((TextDecoration)(lvi.GetSubItem(4).Decoration)).Text = "Live Data";
((TextDecoration)(lvi.GetSubItem(4).Decoration)).DrawText(bg.Graphics, r);
bg.Render(g);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment