开发者

In timer tick event the selected index of combo box becomes the one i hover the mouse on.Why?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜