gpt4 book ai didi

vb.net - 在 vb.net 中动态更改按钮背景颜色

转载 作者:行者123 更新时间:2023-12-04 09:16:23 41 4
gpt4 key购买 nike

我的 .Net 应用程序中有 3 个按钮,我想知道如何动态执行以下代码。

公共(public)类frmTC

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button1.BackColor = Color.Red
Button2.BackColor = Color.Yellow
Button3.BackColor = Color.Yellow
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Button1.BackColor = Color.Yellow
Button2.BackColor = Color.Red
Button3.BackColor = Color.Yellow
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Button1.BackColor = Color.Yellow
Button2.BackColor = Color.Yellow
Button3.BackColor = Color.Red
End Sub

End Class

最佳答案

Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim btn As Button = CType(sender, Button)
SetColor(btn)
End Sub

Private Sub SetColor(Button button)
Button1.BackColor = Color.Yellow
Button2.BackColor = Color.Yellow
Button3.BackColor = Color.Yellow
button.BackColor =Color.Red
End Sub

关于vb.net - 在 vb.net 中动态更改按钮背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29664946/

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