Этот выводит значение по отношению к позиции, в которой был выполнен щелчок на индикаторе выполнения. Диапазон значений здесь рассчитывается от 0 до 100%. Он также зависит от ширины индикатора выполнения, поэтому диапазон будет оставаться фиксированным в процентах.
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);
}
Я знаю, что этот вопрос задавали очень давно, но это было неправильное решение. Вот оно, сейчас.