根据选择重绘工具条
我被要求编写 c# winforms 应用程序,该应用程序将使用户能够从复选框列表中选择选项,并使用所选项目自动重绘/重绘工具条。
我是 winforms 的新手,所以我不知道如何处理它。 我应该使用BackgroundWorker 进程吗? 无效()?
只是有点困惑。
任何指出正确方向的帮助将不胜感激。
I have been asked to write c# winforms app that will give users the ability to select options from a checkbox list and have it automatically redraw/repaint a toolstrip with the selected items.
I am new to winforms so I am not sure how to approach it. Should I be using the BackgroundWorker Process? Invalidate()?
Just alittle confused.
Any assistence of pointing in the right direction would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能不想要一个BackgroundWorker,因为它在非UI 线程上运行,并且当您尝试修改工具条时会导致问题(您只能在创建UI 的线程上使用UI)。 处理复选框上的 CheckedChanged 事件,然后在工具条中添加或删除项目。 重新绘制应该是自动的。
You probably don't want a BackgroundWorker as that's run on a non-UI thread and would cause problems when you try to modify the toolstrip (you can only work with the UI on the thread the UI was created on). Handle the CheckedChanged events on the checkboxes and then add or remove items from the toolstrip. The repainting should be automatic.
您需要将所有选项的工具提示保留在某个位置(如果复选框的 Tag 属性是空闲的,则将其放在那里)。 然后,当选择或取消选择某个选项时,您需要更新工具提示。
假设您要在 IList 中添加所有复选框。 那么事情将按如下方式进行:
现在您需要在选项复选框的 checkedchanged 事件上调用此方法:
You need to keep tooltips for all options some where (if Tag property of checkboxes is free the put it there). Then when an option is selected or deselected, you need to update tooltips.
Let's suppose you are adding all the checkboxes in a IList. then things will work as follows:
Now you need to call this on checkedchanged event of options check boxes:
工具条本身包含控件 - 它不仅仅是“绘制”您可以按下的按钮。 为了让工具条根据不同的条件显示不同的按钮,您可以:
Visible = false
),仅在检查列表框中选择时将必要的设置为Visible = true
无需进行任何绘制:-)
A toolstrip contains controls by itself - it does not just "paint" buttons you can press. In order to have the toolstrip display different buttons depending on different conditions, you can:
Visible = false
) and only set the necessary ones toVisible = true
upon selection in your check listboxNo need to do any painting :-)