gpt4 book ai didi

excel - 用户窗体中命令按钮的自定义颜色

转载 作者:行者123 更新时间:2023-12-04 20:00:04 25 4
gpt4 key购买 nike

我已经成功地在我的用户表单中为一个按钮(commandbutton_1)的字体和背景着色:

Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
CommandButton1.BackColor = RGB(220, 230, 241)
CommandButton1.ForeColor = RGB(0, 0, 0)
End Sub


Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
CommandButton1.BackColor = RGB(22, 54, 92)
CommandButton1.ForeColor = RGB(255, 255, 255)
End Sub

Private Sub UserForm_Activate()
CommandButton1.BackColor = RGB(22, 54, 92)
CommandButton1.ForeColor = RGB(225, 225, 225)
UserForm.BackColor = RGB(22, 54, 92)
End Sub

但是当我将相同的代码应用于我的第二个按钮(CommandButton2)时,它无法正常工作:
Private Sub CommandButton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
CommandButton2.BackColor = RGB(220, 230, 241)
CommandButton2.ForeColor = RGB(0, 0, 0)
End Sub


Private Sub UserForm2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
CommandButton2.BackColor = RGB(22, 54, 92)
CommandButton2.ForeColor = RGB(255, 255, 255)
End Sub

Private Sub UserForm2_Activate()
CommandButton2.BackColor = RGB(22, 54, 92)
CommandButton2.ForeColor = RGB(225, 225, 225)
UserForm.BackColor = RGB(22, 54, 92)
End Sub

最佳答案

只有当第二个命令按钮位于名为 UserForm2 的用户表单中时,您的代码才能工作。这就是您的事件处理程序中的内容:UserForm2_MouseMove
将代码合并到您调用的表单的事件中 UserForm :

Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
CommandButton1.BackColor = RGB(22, 54, 92)
CommandButton1.ForeColor = RGB(255, 255, 255)

CommandButton2.BackColor = CommandButton1.BackColor
CommandButton2.ForeColor = CommandButton1.ForeColor
End Sub

关于excel - 用户窗体中命令按钮的自定义颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33234186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com