带弹出菜单的 ToolStripButton?

发布于 2024-07-13 15:09:46 字数 510 浏览 5 评论 0原文

我正在为一个类似绘画的程序制作 GUI,用户可以从 ToolStrip 中选择绘图工具。 其中一些工具有多种变化,我希望用户能够通过弹出菜单选择一个。

任何熟悉 Photoshop 工具栏界面的人都会知道我在做什么:用户可以单击按钮并开始使用所选工具,或者从单击时出现的弹出菜单中选择一个工具,然后从那时起该按钮将代表该工具。 此外,当选择该工具系列时,该按钮的 Checked 属性将设置为 True。

我认为这可以通过 SplitButton 或 DropDownButton 来完成,但它们没有 Checked 属性供用户查看当前选择的工具。 因此,我使用了 ToolStripButton 和单击时显示的 ContextMenuStrip。

问题是,由于我采用光标位置来显示 ContextMenuStrip,根据单击 ToolStripButton 的哪一部分,弹出菜单可能会部分覆盖它,而且外观非常粗糙。 如何获取 ToolStripButton 的屏幕坐标? 或者有更好的(而且仍然相对简单)的方法来做到这一点?

I'm doing the GUI for a paint-like program, where the user will be able to select a drawing tool from a ToolStrip. Some of these tools have variations, and I'd like the user to be able to select one via a popup menu.

Anyone familiar with the Photoshop toolbar interface will know what I'm after: the user can either click the button and start working with the selected tool, or pick one of the tools from the popup menu that appears upon click, and from that point on the button will represent that tool. Also, the button will have the Checked property set to True when that tool-family is selected.

I thought this could be accomplished with a SplitButton or DropDownButton, but these don't have a Checked property for the user to see what tool is currently selected. So I went with a ToolStripButton and a ContextMenuStrip that is shown upon click.

The problem is that since I'm taking the cursor position to show the ContextMenuStrip, depending on what part of the ToolStripButton is clicked, the popup menu might cover it partially, and it is a very unpolished look. How can I get the ToolStripButton's screen coordinates? Or is there a better (and still relatively simple) way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风来 2024-07-20 15:09:46

我之前已经在应用程序中实现过此类功能。 在 Photoshop 中,每个工具都有不同的图标(套索和多边形套索有不同的图标,画笔和铅笔有不同的图标)。 因此,在使用工具条时,我使用分割按钮。 当用户从下拉列表中选择工具时,您可以将所选工具的图标应用到拆分按钮。

ToolStripItem 可以有背景图像。 要显示所选项目,您只需将背景图像设置为纯色半透明图像(即透明度为 25% 的纯黑色)。

编辑:最好使用 SystemColors.Highlight 的半透明版本

I've implemented this sort of feature before in applications. In Photoshop, each tool has a different icon (lasso and polygonal lasso have different icons, brush and pencil have different icons). So, when using a tool strip, I use a split button. When the user selects a tool from the drop down list, you apply the selected tool's icon to the split button.

A ToolStripItem can have a background image. To show the selected item, you can simply set the background image to a solid-colored semi-transparent image (i.e. solid black with 25% transparency).

edit: It would probably be best to use a semi-transparent version of SystemColors.Highlight

年少掌心 2024-07-20 15:09:46

你没有说你的 GUI 使用什么技术。 我猜是 winform 或 WPF。 如果您有选择,WPF 可能是最佳的长期选择,它不仅支持上下文菜单按钮,还支持应用程序的绘画部分。

如果您使用 winforms,您是否考虑过向主按钮添加上下文菜单?

You don't say what technology you are using for the GUI. I'm guessing winforms or WPF. If you have a choice WPF may be the best long-term choice to support not just your context menu buttons but also to support the painting part of your application.

If you are using winforms, have you looked at adding a context menu to your main buttons?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文