【问题标题】:How do i change the button color in vb.net with an enter action?如何通过输入操作更改 vb.net 中的按钮颜色?
【发布时间】:2016-01-25 10:52:35
【问题描述】:

我添加了一个按钮(名称:btn_exit,操作如下:如果光标离开按钮,它应该变成红色,就像一个信号一样。在我的应用程序中,它不像我想的那样工作。控制台说没有错误。那么我该调整什么来改变颜色呢?

我的代码:

Private Sub btn_exit_Leave(sender As Object, e As EventArgs) Handles btn_exit.Leave
    btn_exit.BackColor = Color.Red
End Sub

【问题讨论】:

  • 问题应该用库标记——[wpf] 或 [winforms]——比 [button] [colors] 和 [action] 有用得多。

标签: vb.net button colors action


【解决方案1】:

你不能用'Leave'事件来做到这一点,你必须使用MouseEnter、MouseHover、MouseLeave事件。

示例代码(刚刚测试过):按钮是“正常的”,直到您第一次将鼠标移到它上面,然后变成蓝色,当您离开鼠标时变成红色背景。

Private Sub Button1_MouseEnter(sender As Object, e As EventArgs) Handles Button1.MouseEnter

    Button1.BackColor = Color.Blue

End Sub

Private Sub Button1_MouseLeave(sender As Object, e As EventArgs) Handles Button1.MouseLeave

    Button1.BackColor = Color.Red

End Sub 

【讨论】:

  • 欢迎您。如果可行,请接受我作为“答案”。
【解决方案2】:

试试这个:

Private Sub Button1_MouseEnter(sender As Object, e As EventArgs) Handles Button1.MouseEnter

  Button1.BackColor = Color.Blue

End Sub

Private Sub Button1_MouseLeave(sender As Object, e As EventArgs) Handles Button1.MouseLeave

  Button1.BackColor = Color.Red

End Sub 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    相关资源
    最近更新 更多