【发布时间】:2015-04-18 16:10:46
【问题描述】:
如何在groupBox1_Paint 中使用timer_lights_status_Tick 方法中的值?
public Main()
{
InitializeComponent();
}
private void groupBox1_Paint(object sender, PaintEventArgs e)
{
// Here is where I want to use those variables: red_light1, yellow_light1…
}
public void timer_lights_status_Tick(object sender, EventArgs e)
{
int red_light1, yellow_light1, green_light1,
red_light2, yellow_light2, green_light2;
red_light1 = Convert.ToInt32(comport.message(4, 8, 32));
yellow_light1 = Convert.ToInt32(comport.message(4, 8, 33));
green_light1 = Convert.ToInt32(comport.message(4, 8, 34));
red_light2 = Convert.ToInt32(comport.message(4, 8, 35));
yellow_light2 = Convert.ToInt32(comport.message(4, 8, 36));
green_light2 = Convert.ToInt32(comport.message(4, 8, 37));
}
【问题讨论】:
-
将“int red_light1”...移到函数之外。您还需要在设置计时器滴答中的所有灯光后调用 this.Invalidate() 以触发重绘。
-
我移动了那条线。你说调用“this.Invalidate()”就像重置一样工作?
-
它不是可以这么说的重置,而是通知控件它需要重绘其客户区,这反过来又会调用您的绘制方法。
标签: c# methods parameter-passing