Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, August 10, 2011

VB-96 : Changing Color as per the entered Number


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 :


===================================================================================

ASSIGNMENT :

Suppose , if you want to include another colour, and you dont know the name of that colour as given below ,
 
Then what will you do ???



This is your assignment..

If failed , see the comment section...to know the answer.

      • ====================================================================
        Back to Home   &  VB
    ===========================================================

    1 comment:

    Priyada Mohanan said...

    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