whats the easiest way to change the progress bar value depending on where you click on the actual bar itself (window media player) in c#?
i use WMP library:confused:

Help me all fri :)
I got problem in my application . i wanna add seek function which is able to control window media player actual bar . when i seek (forward) on my win forms, i want window media player also does seek (forward) . here is my code.

private void progressBar1_Click(object sender, EventArgs e)
        {
            progressBar1.MouseDown += new MouseEventHandler(progressBar1_MouseDown);
            progressBar1.MouseUp += new MouseEventHandler(progressBar1_MouseUp);
        }

        void progressBar1_MouseUp(object sender, MouseEventArgs e)
        {
            
            if (e.Button == MouseButtons.Left)
            {
                isDragging = false;
                double Tracklength = m_Player.axWMP.currentMedia.duration;
                m_Player.axWMP.Ctlcontrols.currentPosition = (Tracklength / 100) * (e.X) ;
                m_Player.axWMP.Ctlcontrols.play();
            }
            
            
        }
        
        void progressBar1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isDragging = true;

                m_Player.axWMP.Ctlcontrols.pause();
                double Tracklength = m_Player.axWMP.currentMedia.duration;
                m_Player.axWMP.Ctlcontrols.currentPosition = (Tracklength / 100) * progressBar1.Value;
                
                
            }
            
        }

I'm not sure is it required timer or not?
Please help me. :(
who wanna help for a such new beginner ???????????????

Thanks in advance :) :)

Firstly, you should attach the event handlers in form load, otherwise, first MouseDown/MouseUp events not captured (event attached after execution).

Second your code uses (e.X) in MouseUp event and progressBar1.Value in MouseDown event. I think both should be the same.

Regarding media player tracking: What other problems do you have with your code?

Dear nick.crane,

Thanks for your reply. now i changed my code as the following.. but still can't make it. How should i do? :(
I do hope for your reply :)

private void FormMain_Load(object sender, EventArgs e)
        {
            
            
            progressBar1.MouseDown += new MouseEventHandler(progressBar1_MouseDown);
            progressBar1.MouseUp += new MouseEventHandler(progressBar1_MouseUp);
            
        }

void progressBar1_MouseUp(object sender, MouseEventArgs e)
        {
            
            if (e.Button == MouseButtons.Left)
            {
                
                double Tracklength = m_Player.axWMP.currentMedia.duration;
                
                m_Player.axWMP.Ctlcontrols.currentPosition = (Tracklength / 100) * progressBar1.Value ;
                timer1.Enabled = true;
                
                
                
            }
             
        }

void progressBar1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                timer1.Enabled = false;
                
                                
                double Tracklength = m_Player.axWMP.currentMedia.duration;
                m_Player.axWMP.Ctlcontrols.currentPosition = (Tracklength / 100) * progressBar1.Value;
                
                
            }
            
        }

private void timer1_Tick(object sender, EventArgs e)
        {if (m_Player.axWMP.playState == WMPLib.WMPPlayState.wmppsPlaying)
            {
                labelTimeCode.Text = m_Player.axWMP.Ctlcontrols.currentPositionString + " / " + m_Player.axWMP.currentMedia.durationString;
            }
        }

Should i use trackbar ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.