好的,所以在表单加载时我调用一个启动计时器的方法,每个tick都假设增加一个整数值并将文本框字段text =设置为integer.ToString,并且由于某种原因它增加4而不是1 ..........
/// <summary>
/// Starts the Timer >:D
/// </summary>
public void StartCounting()
{
t.Interval = 1000;
t.Tick += new System.EventHandler(OnTimerEvent);
t.Start();
}
/// <summary>
/// This is what Happens when the timer ticks.
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
public void OnTimerEvent(object source, EventArgs e)
{
textBoxActual.Text = currentMinute.ToString();
currentMinute = currentMinute + 1 ;
}
绿色的数字是textBoxActual&lt;。&lt;
这是我的表单加载代码:
private void Form1_Load(object sender, EventArgs e)
{
Order o = new Order();
StartedOrders = o.GetUnfinishedOrders();
PopulateGrid(StartedOrders, dataGridViewStartedOrders);
//Set the top row to be some abstract style.
System.Windows.Forms.DataGridViewCellStyle iStyle = new DataGridViewCellStyle();
iStyle.BackColor = Color.Green;
System.Drawing.Font f = new System.Drawing.Font("Times New Roman",13,FontStyle.Bold);
iStyle.Font = f;
dataGridViewStartedOrders.Rows[0].DefaultCellStyle = iStyle;
dataGridViewStartedOrders.ClearSelection();
try
{
textBoxOrderNumber.Text = "O# " + dataGridViewStartedOrders.Rows[0].Cells[1].Value.ToString();
textBoxCustomerName.Text = dataGridViewStartedOrders.Rows[0].Cells[2].Value.ToString();
textBoxTarget.Text = dataGridViewStartedOrders.Rows[0].Cells[5].Value.ToString();
textBoxActual.Text = "0";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
StartCounting();
}
答案 0 :(得分:3)
如果它总是按4更新,我的通灵调试能力会说你正在添加你的听众4次。