In my form, i have a timer,a textbox and a combobox with three items, which display different times in textbox for each time, when the timer ticks. An audio is being played whose time displays on the textbox. I drop down the combobox and hover mouse over one of the item. The time in the text box gets updated according to that item.I want that the time in the text box should only be updated when SelectionChangeCommitted event is called and not while mouse hovers above the items.
The code is:
private void timer_Tick(object sender, EventArgs e)
{
UpdateTime();
}
private void UpdateTime()
{
textbox1.Text = combobox1.SelectedIndex == 0 ? currentTime :
combobox1.SelectedIndex ==1 ? elapsedCurrentTime :
combobox1.SelectedIndex == 2 ?remainingTime开发者_StackOverflow社区;
}
Handle combobox1.SelectionChangeCommitted and keep combobox1.SelectedIndex value in the class member:
currectSelection = combobox1.SelectedIndex;
In UpdateTime method use currectSelection instead of combobox1.SelectedIndex.
精彩评论