画图都是从OnPaint中触发的:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
DrawItems(e);
}
private void DrawItems(PaintEventArgs e)
{
BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
Graphics g = myBuffer.Graphics;
g.Clear(this.BackColor);
//画时间刻度
DrawScales(g);
//画时间字符串
DrawTimeString(g);
//画任务块
DrawTaskItems(g);
//画边框
DrawBorder(g);
//呈现图像至关联的Graphics
myBuffer.Render(e.Graphics);
myBuffer.Dispose();
g.Dispose();
}