Colour BuilderAuthor : Pandu Ranga Rao N
E - Mail : pandu2050@gmail.com

Colours define way of life in our daily routine. There many different colours we see across the globe. Your day begins with sun rising with orange-red colour and perhaps ends with black colour, with the middle day with the blue colour in the wonderful skies. What made me to describe colors is, now, let us see how computer defines and make use of colors in its daily routine.

Computer can understand only ones and zeros. Combination of 0’s and 1’s, forms a human readable format or pattern, which is nothing but, numbers. Human understanding of the color is through a combination of numbers, which can be programmatically applied through the three colours Red, Green, Blue combination. Also, for computers, it’s a special conversion number format can also decide the colour code to be applied. This format is called as Hexadecimal equivalent.

In Visual Basic, there is a provision for converting the applied color into hexadecimal number, which can be used in some other applications such as paint, adobe photoshop etc.



Now, it is more convenient for the users, if they have, little bit exposure to colour codes. Therefore, it is better to have an application developed for users; just to know what colour uses what code.

Now, we will look into application development. In Visual basic, take a blank form and place picture box, vertical scroll bars, 4 labels for Hexadecimal, Red, Green, Blue respectively and place the controls as shown and then write the program code as given below.



Write first lines of code for form’s load event as,


Private Sub Form_Load()
   Picture1.BackColor = RGB(VScroll1.Value, VScroll2.Value, VScroll3.Value)
   Label1.Caption = Hex(Picture1.BackColor)
   Label1.Caption = Format(Label1.Caption, "000000")
   Label2.Caption = VScroll1.Value
   Label3.Caption = VScroll2.Value
   Label4.Caption = VScroll3.Value
End Sub

The above code will apply a color to the background of a picture box control which is generated from the three values which is taken from the three vertical scroll boxes. The labels are assigned with the values of these scroller changed values and also hexadecimal equivalent value of the background colour applied.

In Visual basic, we term every event as a subroutine, and the subroutine can be called in another subroutine or in an event.

Since, we required to do the same operation which is done by the form’s load event, for the three vertical scroll bars, we can just call the subroutine form_load which in turn does what the scroll bars supposed to do when we change the scroller.


Private Sub VScroll1_Change()
   Call Form_Load
End Sub


Private Sub VScroll2_Change()
   Call Form_Load
End Sub


Private Sub VScroll3_Change()
   Call Form_Load
End Sub

Now, we just look into lines of code which enables copying the hexadecimal value of present colour into the clipboard.


Private Sub Command2_Click()
   Clipboard.Clear
   Clipboard.SetText Label1.Caption
End Sub

Finally, the code for exit button goes here,


Private Sub Command1_Click()
   End
End Sub

Now, run the program and enjoy playing around by keep changing the colours.

Click here to download the zip file, colourbuilder.zip, and unzip the contents and Run the program colorbuilder.exe. If you have got Visual basic 6.0, you can also view the form design and source code.


Author : Pandu Ranga Rao N
E - Mail : pandu2050@gmail.com
 
 
 
 
 
 
  About Team ProgrammingBasics.In

Contact Team ProgrammingBasics.In

Instructions for submitting your own article
 
 
X

About Team ProgrammingBasics.In

Right now, we are a small but, dedicated team who strived day and night to alter the pretty old programmingbasics.in into a new conceptual website "The ProgrammingBasics Foundation Library".

The articles and topics in the website are the major contributions of freelancers, programmers across the globe. We thank each of them for their valuable contributions. You can also become a contributor by sending some software related articles to us. We will publish it in our website. Instructions for the same are given in the "Instructions for submitting your own article" page.

Contact Us

ICan Technologies,
HIG 44, 23rd Cross, 8th Main,
E-Block, Vijayanagar 3rd Stage
Mysore-570017, Karnataka, India

Website: www.icantech.in
Mobile: +918050239039

Instructions for submitting your own article

Want to become an article contributor to this site ?

If yes, then send us an article written by you on your own words, neatly typed in MS Word document. If we feel that, you have written the article by using some other article then we will reject the article. Every article we will cross verify, before we publish them. The right to reject the article is with us.

If you want to publish your name and email id's, specify the same in the document.

NOTE: You must give your consent in the email for publishing your email id and your name. Otherwise, your name and email-ids will not get published. We respect your privacy.

One article per document, which means, you must not send more than one article in one document. Everything in the sent document will be treated as one article and your article will get rejected without looking in, further.

The articles must and should be related to computer basics, programming concepts and programming languages. We will not entertain any other topics. Please bear this in your mind, before starting an article write-up.

Articles published in ProgrammingBasics.in are the sole property of ICan Technologies, Mysore. You are here in authorizing ICan Technologies, Mysore to take the ownership of the published article. Rejected articles will not be published and you can try to publish the same in other sites. We will inform you the status of your submitted article within 10 working days, from the date of sent mail. If not responded within 10 days, then you are free to try publishing your article on some other websites. We will simply discard them and will not publish them any further. Once we publish the article, you will not be allowed to publish as it is, in some other website. If we find it, then your article will be removed from site and the removal will be informed to you.

Send your articles to programmingbasics.info@gmail.com with "Article for Publishing" in the subject line.

You must create your own images in PSD (Photoshop Document) only, which is to be supported in CS3 or lower versions. Any animated stuffs, must be in fla files (Flash editable file) and not in any other format and must be readable in Falsh 8.0.

You are now in