在无边框窗体上有一个弹出菜单

发布于 2024-10-24 22:18:23 字数 119 浏览 14 评论 0原文

如何在 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 技术交流群。

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

发布评论

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

评论(3

宁愿没拥抱 2024-10-31 22:18:23

这是可行的,但(对我来说)有些不满意。通过在表单中​​具有任何菜单属性,边框将默认恢复为可见。然而,有一些解决方法:

1)我认为您更喜欢的方法涉及制作您永远不会真正“使用”或看到的第二种形式。将菜单放在第二个窗体上,然后从您实际要使用的窗体中调用该菜单。假设您使用 Form_MouseDown 来调用它,代码如下:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button And vbRightButton Then PopupMenu Form2.mnuYourMenu
End sub

但是,您必须记住从内存中卸载第二个表单。

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:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button And vbRightButton Then PopupMenu Form2.mnuYourMenu
End sub

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 to False and to leave the Caption property blank. This "removes" the border when BorderStyle 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.shtml

Hope this helps!

对不⑦ 2024-10-31 22:18:23

为了让其他来这里寻找此问题答案的人受益,这里有一个非常简单的 API 方法,可以使用:

声明:

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Const GWL_STYLE = -16, WS_BORDER = &H800000

在 Form_Load 中:

SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) And Not WS_BORDER

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:

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Const GWL_STYLE = -16, WS_BORDER = &H800000

In Form_Load:

SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) And Not WS_BORDER
酒与心事 2024-10-31 22:18:23

这是可能的。将窗体的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:

enter image description here

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