2015-01-08 76 views
1

當MCU_timer_Tick()被調用時,我想調用OnPaint()。 我該怎麼辦?如何將EventArgs轉換爲PaintEventArgs,C#

private void MCU_timer_Tick(object sender, EventArgs e) 
    { 
     ... 
    } 
    protected override void OnPaint(PaintEventArgs e) 
    { 
     Graphics g = e.Graphics; 

     int width = 30; 
     int x, y; 
     x = 150; 
     y = 530; 
     double color_max; 
     color_max = 255; 
     SolidBrush aBrush_1 = 
     new SolidBrush(Color.FromArgb(100, 255, 
     (int)(255 * color_map[0]/color_max), 0)); //color_map[0] is real value 
     g.FillEllipse(aBrush_1, x-100, y, width * 2, width); 

回答

4

致電this.Invalidate()Tick事件中。這將最終使Paint事件發生。

private void MCU_timer_Tick(object sender, EventArgs e) 
{ 
    this.Invalidate(); 
} 

其中thisControl。通常是Form