I'm pretty bad at maths and I'm hoping someone can help me with this or explain how it works. I am trying to program a custom progressbar where the location should just change where location x = 1 //0% and location x= 363 //100%. y is always 0
Here is the method I am trying to implement
private void SetProgressValue(int value)
{
// value min = 0;
// value max = 100;
//Location 1, 0 = 0%
//Location 363, 0 = 100%
Point newLocation;
int result = value * 100 / 363;
newLocation = new Point(result, 0);
spanProgress.Location = new Point(newLocation.X, newLocation.Y);
}
CodePudding user response:
You problem is probably that you use ints to calculate fractions.
Suggestion:
float result = (value / 100.0) * 363;