Changing color of form according to the entered number.
Refer Change the background color of the form and Color changing using Timer
(A)Program Design :
(B) Property(Controls Used) :
- One Label with Caption Enter a Number (1 to 5) , Autosize-True , Backstyle - Transparent
- One TextBox (Name-Text1 , Text Property is Blank)
- One Command Button with Caption-Change and Name - Command1
(C) Attaching Code to the Object :
Private Sub Command1_Click()
Dim n As Integer
n = Val(Text1.Text)
Select Case n
Case 1
Form1.BackColor = vbRed
Case 2
Form1.BackColor = vbGreen
Case 3
Form1.BackColor = vbBlue
Case 4
Form1.BackColor = vbYellow
Case Else
Form1.BackColor = vbWhite
End Select
End Sub
|
(D) Output :
===================================================================================
- ====================================================================
1 comment:
If you dont know the particular name of a color, then take the code of that color from the properties.
Select properties --> BackColor , then select the color from the Palette.
=====================================
Private Sub Command1_Click()
Dim n As Integer
n = Val(Text1.Text)
Select Case n
Case 1
Form1.BackColor = &H8080FF
Case 2
Form1.BackColor = &H80FF80
Case 3
Form1.BackColor = &HC000C0
Case 4
Form1.BackColor = &H8000&
Case 5
Form1.BackColor = &H40&
End Select
End Sub
Post a Comment