进度条点击(紧凑框架)
我正在使用进度条来显示电池状态。 如果用户单击进度条,我想显示一个包含详细信息的弹出窗口。
除了需要检查点击坐标是否在进度条范围内的解决方案之外,有人找到了其他解决方案或解决方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,执行自定义控件的一种更简单的方法是从 UserControl 开始,在其上放置一个 ProgressBar 并将其停靠以使其填充 UserControl,然后将 ProgressBar 公开为 UserControl 的公共属性,以便您的代码说
而不是
然后只需使用用户控件的 Click 事件来显示详细信息(我认为您可能必须禁用内部 ProgressBar 才能使单击正常工作,但这不应影响进度栏的外观)。
这样你的用户控件看起来就像一个常规的进度条(因此,就像屁股一样)。 :)
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
instead of
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). :)
此外,仅以用户习惯的方式使用控件通常被认为是良好的形式。 进度条仅用于(并且传统上使用)显示信息。 这就是为什么他们删除了 Compact Framework 中的所有交互事件。
我认为更好的方法是保持进度条不变,并在进度条上方或旁边添加一个“详细信息”链接标签。
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.
我一直只是编写自己的自定义 ProgressBar 用户控件。 写起来大概需要 5 分钟,而且内置的进度条控件无论如何看起来都很糟糕。
我认为可以使用反射来实现此目的,但编写自己的控件会更容易。
更新:我只是尝试将 ProgressBar 转换为控件(它确实有 Click 事件),然后在代码中分配事件处理程序,但这似乎不起作用。
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.