locked
Trackbar GotFocus Events in .net CF RRS feed

  • Question

  • Dear All,

    Iam developing an application in C#.net CF for  windows mobile 6.1. i am using trackbar to trace the music player timing. as we dont have scroll property for track bar i used a static bool variable to identify user scroll and timer tick in valuechange method. Please find my code i need to set the music based on the trackbar's value if the user scrolls it while playing the song.

     private void timer3_Tick(object sender, EventArgs e)
            {
                double curPosition = player.Ctlcontrols.currentPosition;
                int playTimeCount = Convert.ToInt32(curPosition);
                if (playTimeCount < 1)
                {
                    tBar.Maximum = Convert.ToInt32(Convert.ToDecimal(player.currentMedia.duration));
                    tBar.Minimum = 0;
                }
                trackChange = false;
                tBar.Value = Convert.ToInt32(Convert.ToDecimal(player.Ctlcontrols.currentPosition));
            }

    private void tBar_ValueChanged(object sender, EventArgs e)
            {
                if (trackChange)
                {
                    timer3.Enabled = false;
                    player.Ctlcontrols.pause();
                    currentPosition = prgBar.Value;
                    player.Ctlcontrols.currentPosition = Convert.ToDouble(tBar.Value);
                    player.Ctlcontrols.play();
                    timer3.Enabled = true;
                    button1.Focus();
                }
            }
    private void tBar_GotFocus(object sender, EventArgs e)
            {
                trackChange = true;
            } 

    I used gotfocus event to identify user's scroll (by guessing they wont use tabs to change the control focus). It worked fine for first time but not helped in consecutive scroll, so i changed the focus to button but gotfocus in not firing for trackbar.

    Please anyone help me to solve this issue or suggest me a better way to achieve my requirement.  

    Thanks in advance,

    Deepa R.

    Friday, May 21, 2010 1:33 PM

Answers

  • Your problem seems to be that you want to know when the user changes the track bar value, but you do not want to have the event fired when you change the value through playback (timer tick event).

    remove your boolean, remove the GotFocus handler and try doing this:

     

    tbar.ValueChanged -= tBar_ValueChanged;

    tBar.Value = Convert.ToInt32(Convert.ToDecimal(player.Ctlcontrols.currentPosition));

    tbar.ValueChanged += tBar_ValueChanged;

     

    Just remove your event handler before you update the value through the code.  this way whenever the event is fire you know it was the user that did it.

    • Proposed as answer by Alan M_ Friday, May 21, 2010 5:54 PM
    • Marked as answer by DeepaRathinam Saturday, May 22, 2010 6:30 AM
    Friday, May 21, 2010 5:53 PM

All replies

  • Your problem seems to be that you want to know when the user changes the track bar value, but you do not want to have the event fired when you change the value through playback (timer tick event).

    remove your boolean, remove the GotFocus handler and try doing this:

     

    tbar.ValueChanged -= tBar_ValueChanged;

    tBar.Value = Convert.ToInt32(Convert.ToDecimal(player.Ctlcontrols.currentPosition));

    tbar.ValueChanged += tBar_ValueChanged;

     

    Just remove your event handler before you update the value through the code.  this way whenever the event is fire you know it was the user that did it.

    • Proposed as answer by Alan M_ Friday, May 21, 2010 5:54 PM
    • Marked as answer by DeepaRathinam Saturday, May 22, 2010 6:30 AM
    Friday, May 21, 2010 5:53 PM
  • another alternative is to do this...

     

    trackChange = false;

    tBar.Value = Convert.ToInt32(Convert.ToDecimal(player.Ctlcontrols.currentPosition));

    trackChange = true;

     

    and leave the boolean in there.

    Friday, May 21, 2010 6:08 PM
  • Hi Alan,

    Thanks alot. It worked well. Thanks again for your timely idea.

    Regards,

    Deepa R 

    Saturday, May 22, 2010 6:32 AM