在无边框窗体上有一个弹出菜单
如何在 VB 6.0 无边框窗体上添加弹出菜单?
每次添加菜单时,即使将 BorderStyle
设置为 vbBSNone
并且隐藏菜单,边框也会重新出现。
How to add a popup menu on a VB 6.0 borderless form?
Every time I add a menu, the border reappears, even when BorderStyle
is set to vbBSNone
and the menu is hidden.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是可行的,但(对我来说)有些不满意。通过在表单中具有任何菜单属性,边框将默认恢复为可见。然而,有一些解决方法:
1)我认为您更喜欢的方法涉及制作您永远不会真正“使用”或看到的第二种形式。将菜单放在第二个窗体上,然后从您实际要使用的窗体中调用该菜单。假设您使用
Form_MouseDown
来调用它,代码如下:但是,您必须记住从内存中卸载第二个表单。
2) 另一种仅使用第一个表单的方法是将表单的
ControlBox
设置为False
并将Caption
属性留空。当BorderStyle
设置为 0 时,这会“删除”边框...我将删除放在引号中,因为不幸的是它会留下 1 像素的黑线。它看起来不错,但对您来说可能不是一个可行的解决方案。3)最后一种方法是使用
CreatePopupMenu
API,我读到过但自己没有做过任何事情,可以在 http://allapi.mentalis.org/apilist/CreatePopupMenu.shtml希望这有帮助!
It's doable, but somewhat unsatisfying (to me). By having any menu properties in a form, the border will default back to visible. There are, however, a few workarounds:
1) The method I think you'll prefer involves making a second form that you'll never really "use" or see. Put the menu on that second form, and then call that menu from the form you actually want to use. Assuming you're using
Form_MouseDown
to call this, here's the code:You will have to remember to unload this second form from memory, however.
2) Another way, only using the first form, would be to set the form's
ControlBox
toFalse
and to leave theCaption
property blank. This "removes" the border whenBorderStyle
is set to 0... I put removes in quotes because it will unfortunately leave behind a 1-pixel black line. It doesn't look bad, but it might not be a viable solution for you.3) The final way, which I read about but haven't done anything with myself, would be to use the
CreatePopupMenu
API, found at http://allapi.mentalis.org/apilist/CreatePopupMenu.shtmlHope this helps!
为了让其他来这里寻找此问题答案的人受益,这里有一个非常简单的 API 方法,可以使用:
声明:
在 Form_Load 中:
For the benefit of anyone else who comes here looking for an answer to this problem, here is a very simple API method that works:
Declarations:
In Form_Load:
这是可能的。将窗体的BorderStyle 设置为None,Caption 设置为空字符串,ControlBox、MaxButton MinButton 设置为False。然后,使用 VB6 的菜单编辑器创建一个名为“mnuPopup”的顶级菜单,并将其 Visible 属性设置为 False。创建菜单的其余部分作为该顶级菜单的子菜单,并将其 Visible 属性设置为 True。然后,在表单的代码中,您可以使用
PopupMenu menuPopup
显示菜单。它看起来像这样:This is possible. Set the form's BorderStyle to None, Caption to an empty string, ControlBox, MaxButton MinButton to False. Then, using VB6's menu editor, create a top-level menu named "mnuPopup," and set its Visible property to False. Create the rest of the menu as submenus to that top-level menu, setting their Visible properties to True. Then, in the code for the form, you can display the menu with
PopupMenu menuPopup
. It looks like this: