0

I want to use the ProgressBar to show how much fuel is left in a car tank, or how close to the maximum speed of the car we got to, among other factors. To do that I decided to set the value as a percentage (speed of a car is from 0-240 for example, and I turn that into a percentage that can be read by the bar).
Except I don't know how to make the bar take the value that is needed and present it on the bar itself.

I read somewhere that we cannot set our own values to the bar IF they are doubles, it only accepts int values, which might explain why they were turned into percentages.

Thanks for your help.

  • `(int)((double)maxSpeedAchieved / 240.0) * 100.0` will give you a "int" based percentile representation (rather then `0.5`, it will be `50`), so a progress bar using `1-100` as it's range would work with it. I tend to do this conversion internally to the UI, so the model can represent the value as a range of `0-1`. This is kind of an important note - the model shouldn't care about "how" the data is going to be represented – MadProgrammer Apr 18 '18 at 21:47
  • That's exactly what I did, but I guess the question wasn't clear enough; how do I **show** the 50 that you set above? Like how do I link this information to the progress bar so i can see 50% pop up on the GUI? – Ashraf Abi-Said Apr 18 '18 at 21:55
  • Well, that's a question of architecture, but at the most simplest level you need to pass the value from the model to UI - this really is nothing more then passing information from one class to another, which makes the question to broad, as any answer would require a better understanding of "how" you've put your classes together. However, you may like to do some research into the "model-view-controller" and "observer" patterns – MadProgrammer Apr 18 '18 at 22:02

0 Answers0