Progress bar click (Compact framework)
-
06-07-2019 - |
Question
I'm using a progress bar to display the battery status. If the user clicks on the progress bar i want to display a popup with details.
Excluding the solution that requires checking if the click coordonates is in the bounds of the progress bar has anyone found another solution or a workaround to this?
Solution
OK, an easier way to do the custom control is to just start with a UserControl, drop a ProgressBar on it and dock it so that it fills the UserControl, then expose the ProgressBar as a public property of the UserControl, so that your code would say
myProgressBar1.ProgressBar.Max = 100
instead of
progressBar1.Max = 100
Then just use the Click event of the usercontrol to show the details (I think you might have to disable the inner ProgressBar for the click to work, but that shouldn't affect the appearance of the progress bar).
This way your user control looks exactly like a regular progress bar (and, hence, like ass). :)
OTHER TIPS
Also, it's generally considered good form to only use controls in the way that users are accustomed to. Progress bars are meant (and traditionally used) only to display information. This is why they removed all the interaction events in Compact Framework.
I think a better approach would be to leave the progress bar as it is, and add a "Details" LinkLabel above or next to the bar.
I've always just written my own custom ProgressBar usercontrol. It takes maybe 5 minutes to write, and the built-in progress bar control looks like ass anyway.
I think it might be possible to use Reflection for this, but it would easier to just write your own control.
Update: I just tried casting the ProgressBar as a Control (which does have a Click event) and then assigning an event handler in code, but this does not appear to work.