Reputation:
OK, so on form load i call a method that starts a timer, which every tick is suppose to increment an integer value and set a text box field text = to the integer.ToString and for some reason it increment by 4 instead of 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 ;
}
the number in green is textBoxActual <.<
This is my form load code:
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();
}
Upvotes: 0
Views: 216
Reputation: 25126
If it is always updating by 4, my psychic debugging powers say that you're adding your listener 4 times.
Upvotes: 3