使用 ToggleButton 的 false .Value 删除单击时顶部的灰色

发布于 2025-01-09 21:26:53 字数 812 浏览 4 评论 0原文

我试图使 ToggleButton 看起来始终是黑色的,但是当单击时,顶部总是出现这个灰色蒙版(可能是为了“单击”效果)

: sstatic.net/YKl34.png" rel="nofollow noreferrer">没有灰色顶部With the grey on top

我发现使用 ToggleButtonfalse .Value 你可以删除它,但我的问题是现在用户表单我正在使出现在关闭后再次出现。有办法解决这个问题吗? 当您单击按钮时,这是我的子目录:

Private Sub ToggleButton1_Click()

    ToggleButton1.Value = False
    ToggleButton1.Caption = "Afficher l'interface"
    ToggleButton1.ForeColor = RGB(255, 255, 255)
    ToggleButton1.BackColor = RGB(0, 0, 0)
    UF_Interface.Show 'Userform I want to show when you click the button

End Sub

谢谢

I'm trying to make a ToggleButton look always black but when clicked there's always this grey mask appearing on top (probably for the "clicked" effect) :

Without the grey on topWith the grey on top

I found that with the false .Value of the ToggleButton you can remove it but my problem is now that the userform I'm making appear is appearing again once closed. Is there a way to fix that ?
This is my sub for when you click the button :

Private Sub ToggleButton1_Click()

    ToggleButton1.Value = False
    ToggleButton1.Caption = "Afficher l'interface"
    ToggleButton1.ForeColor = RGB(255, 255, 255)
    ToggleButton1.BackColor = RGB(0, 0, 0)
    UF_Interface.Show 'Userform I want to show when you click the button

End Sub

Thanks

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

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

发布评论

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

评论(2

︶ ̄淡然 2025-01-16 21:26:53

如果我可以建议,如果您想使用切换按钮,
也许最好设置两个条件(如果 true 那么什么,如果 false 那么什么),
如下图所示:

在此处输入图像描述

所以在上图中,如果 true 则打开另一个 UF -如果为假那么关闭那个UF。

下面是 ToggleButton 所在的 UF 中的代码:

Private Sub UserForm_Initialize()
    With ToggleButton1
        .Caption = "OPEN UF_Interface"
        .BackColor = vbYellow
    End With
End Sub

Private Sub ToggleButton1_Click()
With ToggleButton1
    If .Value = True Then
        .Caption = "CLOSE UF_Interface"
        .BackColor = vbGreen
        UF_Interface.Show vbModeless
    Else
        .Caption = "OPEN UF_Interface"
        .BackColor = vbYellow
        Unload UF_Interface
    End If
End With
End Sub

两个用户窗体(UF_Interface 和带有切换按钮的窗体)都必须以 vbModeless 状态显示。所以你需要在常规模块中创建另一个子模块,如下所示:

Sub OpenFormWithToggleButton()
FormWithToggleButton.Show vbModeless
End Sub

If I may suggest, if you want to use the ToggleButton,
maybe it's better making a two condition (if true then what, if false then what),
such as the image below :

enter image description here

So in the image above, if true then open the other UF - if false then close that UF.

Below is the code in the UF where the ToggleButton reside :

Private Sub UserForm_Initialize()
    With ToggleButton1
        .Caption = "OPEN UF_Interface"
        .BackColor = vbYellow
    End With
End Sub

Private Sub ToggleButton1_Click()
With ToggleButton1
    If .Value = True Then
        .Caption = "CLOSE UF_Interface"
        .BackColor = vbGreen
        UF_Interface.Show vbModeless
    Else
        .Caption = "OPEN UF_Interface"
        .BackColor = vbYellow
        Unload UF_Interface
    End If
End With
End Sub

Both userforms (UF_Interface and the one with the toggle button) must be shown in vbModeless state. So you need to make another sub in regular module, something like below :

Sub OpenFormWithToggleButton()
FormWithToggleButton.Show vbModeless
End Sub
何以笙箫默 2025-01-16 21:26:53

@karma的帮助下,我这样修改了我的代码(因为我无法更改“正常”按钮的颜色,即使我想要它的工作方式):

Private Sub ToggleButton1_Click()
    With ToggleButton1
        If .Value = True Then
            .Caption = "Afficher l'interface"
            .BackColor = vbBlack
            .Value = False
            UF_Interface.Show 'Userform I wanted to show
        End If
    End With
End Sub

With the help of @karma I modified my code this way (since I couldn't change the color of a "normal" Button even though I wanted it's way of working) :

Private Sub ToggleButton1_Click()
    With ToggleButton1
        If .Value = True Then
            .Caption = "Afficher l'interface"
            .BackColor = vbBlack
            .Value = False
            UF_Interface.Show 'Userform I wanted to show
        End If
    End With
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文