更改Form2的背景颜色

时间:2013-11-13 10:00:39

标签: vb.net background

我有两个RadioButtons一个用于Light Blue,另一个用于Ghost White和一个button来显示下一个表单(Form2) 我希望能够检查Radio Button以及backcolor of form2对已选中Radio Button的更改 这是我到目前为止编码的原因

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    SecondForm.Show()
    End Sub

Private Sub rbLightBlue_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbLightBlue.CheckedChanged
    If rbLightBlue.Checked Then
        SecondForm.BackColor = (Color.LightBlue)
    End If
End Sub

Private Sub rbGhostWhite_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbGhostWhite.CheckedChanged
    If rbGhostWhite.Checked Then
        SecondForm.BackColor = (Color.GhostWhite)
    End If
End Sub

我遇到的问题是在Form2上进行背景颜色更改。 对这个问题的任何答案都会非常有帮助。

1 个答案:

答案 0 :(得分:0)

我不确定你在做什么,它可能与你如何创建你的SecondForm有关,这段代码确实有用,看看它是否有助于你缩小范围。

Public Class Form1
    Dim SecondForm As Form2 = New Form2
    Private Sub rbLightBlue_CheckedChanged(sender As Object, e As EventArgs) Handles rbLightBlue.CheckedChanged
        If DirectCast(sender, RadioButton).Checked Then
            SecondForm.BackColor = Color.LightBlue
        End If
    End Sub

    Private Sub rbGhostWhite_CheckedChanged(sender As Object, e As EventArgs) Handles rbGhostWhite.CheckedChanged
        If DirectCast(sender, RadioButton).Checked Then
            SecondForm.BackColor = Color.GhostWhite
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        SecondForm.Show()
    End Sub
End Class