progress bar click => change current track play position
i am making a music player in winforms. i have a progress bar and when i click on a position along the progress bar, i want to get the int for that position (开发者_Python百科 from 1 to 100 , i.e. for when i want to get to a certain point in my song ) . How can i do that ?
Regards, Alexandru Badescu
Use TrackBar control, and this is may an advance one, I hope it helps you.
Good luck.
Try this:
'Using The Click or MouseDown or any Mouse Event
Dim Value As Integer= Me.PointToClient(MousePosition).X-Progressbar.Bounds.X
Progressbar.value= Value
you can use a control that have to be placed on the progress bar --like a small bullet . now if you use the code
progressbar1.value=control.location.x/y
place the name of the control at the position of control x/y decides the coordinates.
make a note that you have to move the control on the progress bar for simplifications use a picture box and use the keydown event to move it side by side
This one brings up a value in relation to the position where the click was done on the progressbar. The value range here is calculated from 0 to 100%. Its also in relation to the width of the progressbar so the range will stay fixed to percentage logic.
private void progressBar1_Click(object sender, EventArgs e)
{
// Get mouse position(x) minus the width of the progressbar (so beginning of the progressbar is mousepos = 0 //
float absoluteMouse = (PointToClient(MousePosition).X - progressBar1.Bounds.X);
// Calculate the factor for converting the position (progbarWidth/100) //
float calcFactor = progressBar1.Width / (float)progressBar1.Maximum;
// In the end convert the absolute mouse value to a relative mouse value by dividing the absolute mouse by the calcfactor //
float relativeMouse = absoluteMouse / calcFactor;
// Set the calculated relative value to the progressbar //
progressBar1.Value = Convert.ToInt32(relativeMouse);
}
I know this question was asked a long time ago, but it was out of the right solution. Here it is now.
Well you could use a picturebox to simulate a progress bar ... have a method to partially fill it based on current progress, and wire up the MouseDown event (this will provide you with the mouse position which you can then scale accordingly).
精彩评论